
> sink(con, append=TRUE, type="message")

> library(tictoc)

> tic()

> # create directories to store output
> if(!dir.exists('results')){
+ dir.create("results")
+ }

> if(!dir.exists('figures')){
+   dir.create("figures")
+ }

> if(!dir.exists('tables')){
+   dir.create("tables")
+ }

> #### Figure 1
> rm(list=ls())

> gc()
         used (Mb) gc trigger  (Mb) limit (Mb) max used  (Mb)
Ncells 547947 29.3    1577734  84.3         NA  1577734  84.3
Vcells 945261  7.3   28586164 218.1      16384 37154796 283.5

> source('Fig1.R', echo = T,  max.deparse.length=10000)

> rm(list=ls())

> gc()
         used (Mb) gc trigger  (Mb) limit (Mb) max used  (Mb)
Ncells 549730 29.4    1577734  84.3         NA  1577734  84.3
Vcells 957021  7.4   22868932 174.5      16384 37154796 283.5

> theme_minimal_panel <- function(base_size = 11, base_family = "",
+                           base_line_size = base_size / 22,
+                           base_rect_size = base_size / 22) {
+   # Starts with theme_bw and remove most parts
+   theme_bw(
+     base_size = base_size,
+     base_family = base_family,
+     base_line_size = base_line_size,
+     base_rect_size = base_rect_size
+   ) %+replace%
+     theme(
+       axis.ticks      = element_blank(),
+       legend.background = element_blank(),
+       legend.key        = element_blank(),
+       panel.background  = element_blank(),
+       panel.border      = element_rect(fill = NA, colour = "black", size = .1),
+       strip.background  = element_blank(),
+       plot.background   = element_blank(),
+       
+       complete = TRUE
+     )
+ }

> library(Hmisc)
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: ‘Hmisc’

The following objects are masked from ‘package:base’:

    format.pval, units


> library(tidyverse)
── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.2 ──
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
✔ purrr   1.0.1      
── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter()    masks stats::filter()
✖ dplyr::lag()       masks stats::lag()
✖ dplyr::src()       masks Hmisc::src()
✖ dplyr::summarize() masks Hmisc::summarize()

> library(ggplot2)

> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> plt_data = c(NA, NA, NA, NA, NA)

> for(state in states){
+   f = paste0('rdd_',state,'.Rdata')
+     load(f)
+     
+ plt= as.data.frame(
+       cbind(rep(as.Date(data$dob),3*8),
+             c(data$white, data$black, data$hispanic,
+                data$democrat_white, data$democrat_black, data$democrat_hispanic,
+              data$republican_white, data$republican_black, data$republican_hispanic,
+                data$vote.gen2008_white, data$vote.gen2008_black, data$vote.gen2008_hispanic,
+                data$vote.gen2010_white, data$vote.gen2010_black, data$vote.gen2010_hispanic,
+                data$vote.gen2012_white, data$vote.gen2012_black, data$vote.gen2012_hispanic,
+                data$vote.gen2014_white, data$vote.gen2014_black, data$vote.gen2014_hispanic,
+                data$vote.gen2016_white, data$vote.gen2016_black, data$vote.gen2016_hispanic
+               ),
+ 
+             rep(c( rep("white",nrow(data)), rep("black", nrow(data)), rep("hispanic", nrow(data))),8),
+             c(rep("Registered",nrow(data)*3),
+               rep("Democrat",nrow(data)*3),
+               rep("Republican",nrow(data)*3),
+               rep("Vote 2008",nrow(data)*3),
+               rep("Vote 2010",nrow(data)*3),
+               rep("Vote 2012",nrow(data)*3),
+               rep("Vote 2014",nrow(data)*3),
+               rep("Vote 2016",nrow(data)*3)
+               
+               )
+             
+             
+             
+             )
+       
+       ,stringsAsFactors = F)
+     colnames(plt)= c("dob", "count", "race", "outcome")
+     plt$state = state
+     plt_data = rbind(plt_data,plt)
+     print(state)
+   
+ }
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"

> plt_data$dob = as.Date(as.integer(plt_data$dob), origin="1970-01-01")

> plt_data=plt_data[-1,]

> plt_data$count = as.integer(plt_data$count)

> plt_data = as_tibble(plt_data)

> fullplt = plt_data %>%
+   as_tibble%>%
+   group_by(dob, outcome, race) %>% dplyr::summarize(count = sum(count,na.rm=T))
`summarise()` has grouped output by 'dob', 'outcome'. You can override using the `.groups` argument.

> fullplt$cutoff = ifelse(fullplt$dob <= as.Date("1990-11-04"),1,0)

> fullplt$running = as.numeric(fullplt$dob - as.Date("1990-11-04"))

> the_names=list(
+   'Black'="Black",
+   'Hispanic'="Hispanic",
+   'White'="White",
+   'Vote 2008'="Vote 2008",
+   'Vote 2010'="Vote 2010",
+   'Vote 2012'="Vote 2012",
+   'Vote 2014'="Vote 2014",
+   'Vote 2016'="Vote 2016"
+ )

> get_label <- function(variable,value){
+   return(the_names[value])
+ }

> data=fullplt[!is.na(fullplt$dob) & (fullplt$running >= -365 & fullplt$running <= 365) & fullplt$outcome %in% c("Vote 2008", "Vote 2010", "Vote 2012","Vote 2014", "Vote 2016"),]%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'Hispanic', 'White')))%>%
+   group_by(race)%>%
+   mutate(ymin = min(count), ymax = max(count),
+          outcome = paste(gsub('Vote ','' , outcome), 'Election'))

> ggsave(filename = "figures/Fig1.pdf", width = 9, height = 7,
+ plot = ggplot(data = data,
+            mapping=aes(x = dob, y = count, group= factor(cutoff), linetype=race, shape = race))+
+   geom_smooth(color="black", span = 1,  fill = "lightgrey")+
+   geom_point(alpha=.05,shape=21)+
+   geom_vline(xintercept = as.Date("1990-11-04"), linetype = "dashed") + 
+   xlab(NULL)+
+   ylab('Votes')+
+   scale_linetype_manual(values=c('solid', 'dashed', 'dotdash'))+
+   scale_x_date(date_breaks = "7 months", date_labels =  "%b \n %Y")+
+   theme_minimal_panel()+
+  guides(linetype='none')+
+   geom_blank(aes(y = ymin)) +
+   geom_blank(aes(y = ymax))+
+   theme(axis.text.y=element_text(face='bold'), axis.title.y=element_text(face='bold', size =14), 
+         strip.text.x = element_text(face='bold', size =14),strip.text.y = element_text(face='bold', size =14),
+         axis.text.x = element_text(face="bold"), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank())+
+    facet_grid(race~outcome, 
+              scales = "free_y" 
+   ) +
+   NULL
+ )
`geom_smooth()` using method = 'loess' and formula 'y ~ x'

> #### Figures 2 and 3, Tables 1 and 2, Figures S1-S4 and Figure S10 Figures S24-S25
> rm(list=ls())

> gc()
          used  (Mb) gc trigger  (Mb) limit (Mb)  max used  (Mb)
Ncells 2699740 144.2    4948840 264.3         NA   4948840 264.3
Vcells 4585038  35.0   97048344 740.5      16384 121310429 925.6

> source('primary_analysis_state_loop.R', echo = T,  max.deparse.length=10000)

> require(rddtools)
Loading required package: rddtools
Loading required package: AER
Loading required package: car
Loading required package: carData

Attaching package: ‘car’

The following object is masked from ‘package:dplyr’:

    recode

The following object is masked from ‘package:purrr’:

    some

Loading required package: lmtest
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: sandwich
Loading required package: np
Nonparametric Kernel Methods for Mixed Datatypes (version 0.60-16)
[vignette("np_faq",package="np") provides answers to frequently asked questions]
[vignette("np",package="np") an overview]
[vignette("entropy_np",package="np") an overview of entropy-based methods]

Please consider citing R and rddtools,
citation()
citation("rddtools")


> require(AER)

> require(tidyverse)

> require(rdrobust)
Loading required package: rdrobust

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

>  states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> for(state in states){
+   file = paste0('rdd_',state,'.Rdata')
+     load(file)
+     source('primary_analysis_rdd.R')
+     print(state)
+ 
+ 
+ }
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"

> source('Fig2_Fig3_Tab1_Tab2_FigS1_FigS2_FigS3_FigS4_FigS10_FigS24_FigS25.R', echo = T,  max.deparse.length=10000)

> rm(list=ls())

> library(tidyverse)

> library(plyr)
------------------------------------------------------------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
------------------------------------------------------------------------------------------------------------------------------------

Attaching package: ‘plyr’

The following objects are masked from ‘package:dplyr’:

    arrange, count, desc, failwith, id, mutate, rename, summarise, summarize

The following object is masked from ‘package:purrr’:

    compact

The following objects are masked from ‘package:Hmisc’:

    is.discrete, summarize


> library(scales)

Attaching package: ‘scales’

The following object is masked from ‘package:purrr’:

    discard

The following object is masked from ‘package:readr’:

    col_factor


> library(dplyr)

> library(rmeta)

> library(xtable)

Attaching package: ‘xtable’

The following objects are masked from ‘package:Hmisc’:

    label, label<-


> # This script outputs:
>   # Figures 2, 3, 
>   # Tables 1, 2
> 
> 
> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> results = as.data.frame(matrix(nrow = 0, ncol = 7))

> colnames(results) = c("coef", "se", "race", "dv", "p value", "endog", "state")

> for(state in states){
+   f = paste0('results/results_',state,'.Rdata')
+   
+   load(f)
+   holder = as.data.frame(matrix(nrow = 36, ncol = 7))
+   colnames(holder) = c("coef", "se", "race", "dv", "p value", "endog", "state")
+   
+   holder$coef = c(ivmod1_white$cace, ivmod1_black$cace, ivmod1_hispanic$cace,
+                    ivmod2_white$cace,  ivmod2_black$cace, ivmod2_hispanic$cace,
+                    ivmod3_white$cace,  ivmod3_black$cace, ivmod3_hispanic$cace,
+                    ivmod4_white$cace,  ivmod4_black$cace, ivmod4_hispanic$cace,
+                    ivmod5_white$cace,  ivmod5_black$cace, ivmod5_hispanic$cace,
+                    ivmod6_white$cace,  ivmod6_black$cace, ivmod6_hispanic$cace,
+                    ivmod_rep_white$cace,  ivmod_rep_black$cace, ivmod_rep_hispanic$cace,
+                   
+                    
+                    
+                   ivmod1_white_f12$cace,  ivmod1_black_f12$cace, ivmod1_hispanic_f12$cace,
+                    ivmod2_white_f12$cace,  ivmod2_black_f12$cace, ivmod2_hispanic_f12$cace,
+                     ivmod5_white_f12$cace,  ivmod5_black_f12$cace, ivmod5_hispanic_f12$cace,
+                     ivmod6_white_f12$cace,  ivmod6_black_f12$cace, ivmod6_hispanic_f12$cace,
+                     ivmod_rep_white_f12$cace,  ivmod_rep_black_f12$cace, ivmod_rep_hispanic_f12$cace
+                    
+                    
+                    
+                    
+                    
+                    )
+   
+   holder$se = c(ivmod1_white$se,  ivmod1_black$se, ivmod1_hispanic$se,
+                 ivmod2_white$se,  ivmod2_black$se, ivmod2_hispanic$se,
+                 ivmod3_white$se,  ivmod3_black$se, ivmod3_hispanic$se,
+                 ivmod4_white$se,  ivmod4_black$se, ivmod4_hispanic$se,
+                 ivmod5_white$se,  ivmod5_black$se, ivmod5_hispanic$se,
+                 ivmod6_white$se,  ivmod6_black$se, ivmod6_hispanic$se,
+                 ivmod_rep_white$se,  ivmod_rep_black$se, ivmod_rep_hispanic$se,
+                 
+                 
+                 
+                ivmod1_white_f12$se,  ivmod1_black_f12$se, ivmod1_hispanic_f12$se,
+                ivmod2_white_f12$se,  ivmod2_black_f12$se, ivmod2_hispanic_f12$se,
+                 ivmod5_white_f12$se,  ivmod5_black_f12$se, ivmod5_hispanic_f12$se,
+                 ivmod6_white_f12$se,  ivmod6_black_f12$se, ivmod6_hispanic_f12$se,
+                 ivmod_rep_white_f12$se,  ivmod_rep_black_f12$se, ivmod_rep_hispanic_f12$se
+                 
+                 
+                 
+                  
+                  
+                  
+   )
+   
+   holder$`p value` = c(ivmod1_white$summary$coefficients[2,4],  ivmod1_black$summary$coefficients[2,4], ivmod1_hispanic$summary$coefficients[2,4],
+                        ivmod2_white$summary$coefficients[2,4],  ivmod2_black$summary$coefficients[2,4], ivmod2_hispanic$summary$coefficients[2,4],
+                        ivmod3_white$summary$coefficients[2,4],  ivmod3_black$summary$coefficients[2,4], ivmod3_hispanic$summary$coefficients[2,4],
+                        ivmod4_white$summary$coefficients[2,4],  ivmod4_black$summary$coefficients[2,4], ivmod4_hispanic$summary$coefficients[2,4],
+                        ivmod5_white$summary$coefficients[2,4],  ivmod5_black$summary$coefficients[2,4], ivmod5_hispanic$summary$coefficients[2,4],
+                        ivmod6_white$summary$coefficients[2,4],  ivmod6_black$summary$coefficients[2,4], ivmod6_hispanic$summary$coefficients[2,4],
+                        ivmod_rep_white$summary$coefficients[2,4],  ivmod_rep_black$summary$coefficients[2,4], ivmod_rep_hispanic$summary$coefficients[2,4],
+                        
+                        
+                        
+                        ivmod1_white_f12$summary$coefficients[2,4],  ivmod1_black_f12$summary$coefficients[2,4], ivmod1_hispanic_f12$summary$coefficients[2,4],
+                        ivmod2_white_f12$summary$coefficients[2,4],  ivmod2_black_f12$summary$coefficients[2,4], ivmod2_hispanic_f12$summary$coefficients[2,4],
+                        ivmod5_white_f12$summary$coefficients[2,4],  ivmod5_black_f12$summary$coefficients[2,4], ivmod5_hispanic_f12$summary$coefficients[2,4],
+                        ivmod6_white_f12$summary$coefficients[2,4],  ivmod6_black_f12$summary$coefficients[2,4], ivmod6_hispanic_f12$summary$coefficients[2,4],
+                        ivmod_rep_white_f12$summary$coefficients[2,4],  ivmod_rep_black_f12$summary$coefficients[2,4], ivmod_rep_hispanic_f12$summary$coefficients[2,4]
+                        
+                        
+                        
+                         
+                         
+   )
+  
+   ##############
+   holder$race = c(rep(c("white", "black", "hispanic"), 12))
+   
+   holder$dv = c(c(rep("Vote 2016", 3),
+                  rep("Vote 2014", 3),
+                  rep("Vote 2012", 3),
+                  rep("Vote 2010", 3),
+                  rep("Democrat", 3),
+                  rep("Registered", 3),
+                  rep("Republican", 3)),
+                  
+                  c(rep("Vote 2016", 3),
+                    rep("Vote 2014", 3),
+                    rep("Democrat", 3),
+                    rep("Registered", 3),
+                    rep("Republican", 3))
+                  
+                  )
+   
+   
+   holder$endog = c(rep("Vote 2008", 7*3),
+                     rep("Vote 2012", 5*3))
+   holder$state = state
+ 
+   
+   results = rbind(results, holder)
+   
+   print(f); print(nrow(results))
+ }
[1] "results/results_al.Rdata"
[1] 36
[1] "results/results_ar.Rdata"
[1] 72
[1] "results/results_ca.Rdata"
[1] 108
[1] "results/results_ct.Rdata"
[1] 144
[1] "results/results_fl.Rdata"
[1] 180
[1] "results/results_il.Rdata"
[1] 216
[1] "results/results_in.Rdata"
[1] 252
[1] "results/results_ks.Rdata"
[1] 288
[1] "results/results_ky.Rdata"
[1] 324
[1] "results/results_ma.Rdata"
[1] 360
[1] "results/results_md.Rdata"
[1] 396
[1] "results/results_mo.Rdata"
[1] 432
[1] "results/results_ne.Rdata"
[1] 468
[1] "results/results_nv.Rdata"
[1] 504
[1] "results/results_ny.Rdata"
[1] 540
[1] "results/results_oh.Rdata"
[1] 576
[1] "results/results_or.Rdata"
[1] 612
[1] "results/results_pa.Rdata"
[1] 648
[1] "results/results_ri.Rdata"
[1] 684
[1] "results/results_sc.Rdata"
[1] 720
[1] "results/results_tn.Rdata"
[1] 756
[1] "results/results_tx.Rdata"
[1] 792
[1] "results/results_va.Rdata"
[1] 828
[1] "results/results_wa.Rdata"
[1] 864
[1] "results/results_wv.Rdata"
[1] 900

> rm(list=ls()[grepl('mod',ls())])

> gc()
          used  (Mb) gc trigger   (Mb) limit (Mb)  max used   (Mb)
Ncells 3117559 166.5    4948840  264.3         NA   4948840  264.3
Vcells 5433799  41.5  167219798 1275.8      16384 209024557 1594.8

> # save state-level results for later modeling
> write_csv(results,'results/main_state_results.csv')
[1mwrote[0m [32m729.00B[0m in [36m 0s[0m, [32m145.60MB/s[0m                                                                                                                                    [1mwrote[0m [32m1.00TB[0m in [36m 0s[0m, [32m95.97TB/s[0m                                                                                                                                    
> # all races
> ggsave(filename= 'figures/Fig2.pdf', width = 9, height = 5, 
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race))%>%
+   filter(endog=='Vote 2008', grepl('Vote', dv))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   mutate( dv = paste(gsub('Vote ', '', dv),' Election')) %>%  
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, linetype = race, fill = race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+  guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dashed', 'dotdash', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.05,0.45)+
+   theme(axis.text.y=element_blank(), axis.title.y=element_blank(), 
+         strip.text.x = element_text(face='bold', size =14),strip.text.y = element_text(face='bold', size =14),
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank())+
+   facet_wrap(dv ~ ., nrow = 4)
+ )

> ggsave(filename = 'figures/FigS2.pdf', width = 9, height = 5,
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race))%>%
+   filter(endog=='Vote 2012', grepl('Vote', dv))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   mutate( dv = paste(gsub('Vote ', '', dv),' Election')) %>%  
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, linetype = race, fill = race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dashed', 'dotdash', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.05,0.45)+
+   theme(axis.text.y=element_blank(), axis.title.y=element_blank(), 
+         strip.text.x = element_text(face='bold', size =14),strip.text.y = element_text(face='bold', size =14),
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank())+
+   facet_wrap(dv ~ ., nrow = 2)
+ )

> ggsave(filename = 'figures/FigS4.pdf', width = 9, height = 5, 
+ plot =results %>%
+   mutate(race=Hmisc::capitalize(race),
+          dv=factor(dv, levels = c("Vote 2016",   "Vote 2014"  , "Vote 2012" ,  "Vote 2010" , "Registered" , "Democrat" ,   
+                                   "Republican", "Major Party")))%>%
+   filter(endog=='Vote 2008', race!='Non-black', dv%in%c('Registered', 'Democrat', 'Republican'))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, linetype = race, fill = race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dashed', 'dotdash', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.3,1)+
+   theme(axis.text.y=element_blank(), axis.title.y=element_blank(), 
+         strip.text.x = element_text(face='bold', size =14),strip.text.y = element_text(face='bold', size =14),
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank())+
+   facet_wrap(dv ~ ., nrow = 3)
+ )

> ### Weighted Average of State CACEs
> 
> predictions_white = as.data.frame(matrix(NA, ncol = 5))

> predictions_black = as.data.frame(matrix(NA, ncol = 5))

> predictions_hispanic = as.data.frame(matrix(NA, ncol = 5))

> colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_black) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_hispanic) = c("ev", "dv", "coef", "se", "race")

> predictions_white$race = "white"

> predictions_black$race = "black"

> predictions_hispanic$race = "hispanic"

> data = results

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white"  & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]])
+       predictions_black = rbind(predictions_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_black$est, preds_black$se, "black"))
+       
+       preds_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic"  & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$dv == unique(data$dv)[j]])
+       predictions_hispanic = rbind(predictions_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_hispanic$est, preds_hispanic$se, "hispanic"))
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_white, predictions_black, predictions_hispanic)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> plt = meta_plot%>%filter(ev == "Vote 2008" & race != "all" & !is.na(race))%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')))

> ggsave(filename = "figures/Fig3.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c("Vote 2010", "Vote 2012", "Vote 2014", "Vote 2016"),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2010", "2012", "2014", "2016"))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> ### Table
>  results %>% 
+    dplyr::filter(dv %in% c('Vote 2010', 'Vote 2012') & endog == 'Vote 2008')%>%
+    dplyr::group_by(dv,state)%>%
+    dplyr::mutate(bold = as.numeric(race == 'black' & 
+                                      `p value` < 0.05 & 
+                                      (coef > coef[race == 'white'] | (`p value`[race == 'white'] >= 0.05)) &
+                                      (coef > coef[race == 'hispanic'] | (`p value`[race == 'hispanic'] >= 0.05)  )))%>%
+    ungroup %>%
+   mutate(state = toupper(state), 
+          race = Hmisc::capitalize(race),
+          coef  = round(coef,3),
+          se = round(se,3)
+            
+   ) %>%
+   mutate(
+          coef = ifelse(bold == 1, paste0('\\textbf{', coef,'}'), as.character(coef)),
+          se = ifelse(bold == 1, paste0('\\textbf{', paste0('(',se,')'),'}'), paste0('(',se,')'))
+   )%>%
+   select(state, dv, race, coef, se)%>%  
+   pivot_wider(names_from = c('dv','race'),
+               values_from = c('coef','se'),
+               id_cols = 'state')%>%
+   select(state, 
+          `coef_Vote 2010_White`,
+          `se_Vote 2010_White`,
+          `coef_Vote 2010_Black`,
+          `se_Vote 2010_Black`,
+          `coef_Vote 2010_Hispanic`,
+          `se_Vote 2010_Hispanic`,
+          
+          `coef_Vote 2012_White`,
+          `se_Vote 2012_White`,
+          `coef_Vote 2012_Black`,
+          `se_Vote 2012_Black`,
+          `coef_Vote 2012_Hispanic`,
+          `se_Vote 2012_Hispanic`)%>%
+   bind_rows(
+     meta_plot %>% 
+       dplyr::filter(dv %in% c('Vote 2010', 'Vote 2012') & ev == 'Vote 2008')%>%
+       dplyr::group_by(dv)%>%
+       dplyr::mutate(bold = as.numeric(race == 'black' & 
+                                  (coef > coef[race == 'white'])  &
+                                  (coef > coef[race == 'hispanic']) ))  %>%
+    ungroup %>%
+       mutate(state = 'Meta', 
+              race = Hmisc::capitalize(race),
+              coef  = round(coef,3),
+              se = round(se,3)
+              
+       ) %>%
+       mutate(
+         coef = ifelse(bold == 1, paste0('\\textbf{', coef,'}'), as.character(coef)),
+         se = ifelse(bold == 1, paste0('\\textbf{', paste0('(',se,')'),'}'), paste0('(',se,')'))
+       )%>%
+       select( state, dv, race, coef, se)%>%
+       pivot_wider(names_from = c('dv','race'),
+                   values_from = c('coef','se'),
+                   id_cols = 'state')%>%
+       select(state, 
+              `coef_Vote 2010_White`,
+              `se_Vote 2010_White`,
+              `coef_Vote 2010_Black`,
+              `se_Vote 2010_Black`,
+              `coef_Vote 2010_Hispanic`,
+              `se_Vote 2010_Hispanic`,
+              
+              `coef_Vote 2012_White`,
+              `se_Vote 2012_White`,
+              `coef_Vote 2012_Black`,
+              `se_Vote 2012_Black`,
+              `coef_Vote 2012_Hispanic`,
+              `se_Vote 2012_Hispanic`))%>%
+   xtable(digits = 3, align = 'cccccccc|cccccc')%>%
+   print(row.names = F, file = 'tables/Tab1.tex')

> results %>% 
+   dplyr::filter(dv %in% c('Vote 2014', 'Vote 2016') & endog == 'Vote 2008')%>%
+   dplyr::group_by(dv,state)%>%
+   dplyr::mutate(bold = as.numeric(race == 'black' & 
+                                     `p value` < 0.05 & 
+                                     (coef > coef[race == 'white'] | (`p value`[race == 'white'] >= 0.05)) &
+                                     (coef > coef[race == 'hispanic'] | (`p value`[race == 'hispanic'] >= 0.05)  )))%>%
+   ungroup %>%
+   mutate(state = toupper(state), 
+          race = Hmisc::capitalize(race),
+          coef  = round(coef,3),
+          se = round(se,3)
+   ) %>%
+   mutate(
+     coef = ifelse(bold == 1, paste0('\\textbf{', coef,'}'), as.character(coef)),
+     se = ifelse(bold == 1, paste0('\\textbf{', paste0('(',se,')'),'}'), paste0('(',se,')'))
+   )%>%
+   select(state, dv, race, coef, se)%>%  
+   pivot_wider(names_from = c('dv','race'),
+               values_from = c('coef','se'),
+               id_cols = 'state')%>%
+   select(state, 
+          `coef_Vote 2014_White`,
+          `se_Vote 2014_White`,
+          `coef_Vote 2014_Black`,
+          `se_Vote 2014_Black`,
+          `coef_Vote 2014_Hispanic`,
+          `se_Vote 2014_Hispanic`,
+          
+          `coef_Vote 2016_White`,
+          `se_Vote 2016_White`,
+          `coef_Vote 2016_Black`,
+          `se_Vote 2016_Black`,
+          `coef_Vote 2016_Hispanic`,
+          `se_Vote 2016_Hispanic`)%>%
+   bind_rows(
+     meta_plot %>% 
+       dplyr::filter(dv %in% c('Vote 2014', 'Vote 2016') & ev == 'Vote 2008')%>%
+       dplyr::group_by(dv)%>%
+       dplyr::mutate(bold = as.numeric(race == 'black' & 
+                                         (coef > coef[race == 'white'] ) &
+                                         (coef > coef[race == 'hispanic']   )))%>%
+       ungroup %>%
+       mutate(state = 'Meta', 
+              race = Hmisc::capitalize(race),
+              coef  = round(coef,3),
+              se = round(se,3)
+              
+       ) %>%
+       mutate(
+         coef = ifelse(bold == 1, paste0('\\textbf{', coef,'}'), as.character(coef)),
+         se = ifelse(bold == 1, paste0('\\textbf{', paste0('(',se,')'),'}'), paste0('(',se,')'))
+       )%>%
+       select( state, dv, race, coef, se)%>%
+       pivot_wider(names_from = c('dv','race'),
+                   values_from = c('coef','se'),
+                   id_cols = 'state')%>%
+       select(state, 
+              `coef_Vote 2014_White`,
+              `se_Vote 2014_White`,
+              `coef_Vote 2014_Black`,
+              `se_Vote 2014_Black`,
+              `coef_Vote 2014_Hispanic`,
+              `se_Vote 2014_Hispanic`,
+              
+              `coef_Vote 2016_White`,
+              `se_Vote 2016_White`,
+              `coef_Vote 2016_Black`,
+              `se_Vote 2016_Black`,
+              `coef_Vote 2016_Hispanic`,
+              `se_Vote 2016_Hispanic`)
+     
+   )%>%
+   xtable(digits = 3, align = 'cccccccc|cccccc')%>%
+   print(row.names = F, file = 'tables/Tab2.tex')

> ## 2012 effects
> plt = meta_plot%>%filter(ev == "Vote 2012" & race != "all" & !is.na(race))%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')))

> ggsave(filename = "figures/FigS1.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c( "Vote 2014", "Vote 2016"),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2012 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2014", "2016"))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> ## Make Tables 1 and 2
> 
> # Table 1: 2010 and 2012 voting outcomes
> 
> 
> 
> 
> ################## States that record race
> plt = results%>%filter(endog == "Vote 2008" & race %in% c('white', 'hispanic', 'black') & !is.na(race) & state %in% c('sc', 'al', 'fl'))%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')),
+          state = toupper(state))

> ggsave(filename = "figures/FigS10.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c("Vote 2010", "Vote 2012", "Vote 2014", "Vote 2016"),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2010", "2012", "2014", "2016"))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   facet_wrap(state~., nrow = 3)
+ )

> ################## States that record pid
> pid.states = read_csv('state_fips.csv')%>%
+   filter(record_pid==1)%>%
+   pull(state_abbr)%>%
+   tolower()
[1mindexing[0m [34mstate_fips.csv[0m [=========================================================================================] [32m1.05GB/s[0m, eta: [36m 0s[0m                                                                                                                                                                         Rows: 51 Columns: 11
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): state_name, state_abbr, long_name, region_name, division_name
dbl (6): fips, sumlev, region, division, state, record_pid

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

> # registration weighted average effect
> predictions_white = as.data.frame(matrix(NA, ncol = 5))

> predictions_black = as.data.frame(matrix(NA, ncol = 5))

> predictions_hispanic = as.data.frame(matrix(NA, ncol = 5))

> colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_black) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_hispanic) = c("ev", "dv", "coef", "se", "race")

> predictions_white$race = "white"

> predictions_black$race = "black"

> predictions_hispanic$race = "hispanic"

> data = results %>%
+   filter(dv=='Registered')

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white"  & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]])
+       predictions_black = rbind(predictions_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_black$est, preds_black$se, "black"))
+       
+       preds_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic"  & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$dv == unique(data$dv)[j]])
+       predictions_hispanic = rbind(predictions_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_hispanic$est, preds_hispanic$se, "hispanic"))
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_white, predictions_black, predictions_hispanic)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> plt1 = meta_plot%>%filter(ev == "Vote 2008" )%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')))

> predictions_white = as.data.frame(matrix(NA, ncol = 5))

> predictions_black = as.data.frame(matrix(NA, ncol = 5))

> predictions_hispanic = as.data.frame(matrix(NA, ncol = 5))

> colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_black) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_hispanic) = c("ev", "dv", "coef", "se", "race")

> predictions_white$race = "white"

> predictions_black$race = "black"

> predictions_hispanic$race = "hispanic"

> data = results %>%
+   filter(state %in% pid.states & dv !='Registered')

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white"  & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]])
+       predictions_black = rbind(predictions_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_black$est, preds_black$se, "black"))
+       
+       preds_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic"  & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$dv == unique(data$dv)[j]])
+       predictions_hispanic = rbind(predictions_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_hispanic$est, preds_hispanic$se, "hispanic"))
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_white, predictions_black, predictions_hispanic)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> plt2 = meta_plot%>%filter(ev == "Vote 2008" )%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')))

> plt = rbind(plt1,plt2)

> ggsave(filename = "figures/FigS3.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c("Registered", 'Democrat', 'Republican'),]%>%
+          mutate(dv = factor(dv, levels = c('Registered', 'Democrat', 'Republican'))), aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Registration') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("Registered", "Democrat", 'Republican'))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> ggsave(filename = 'figures/FigS4.pdf', width = 9, height = 5, 
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race),
+          dv=factor(dv, levels = c("Vote 2016",   "Vote 2014"  , "Vote 2012" ,  "Vote 2010" , "Registered" , "Democrat" ,   
+                                   "Republican", "Major Party")))%>%
+   filter(endog=='Vote 2008', race!='Non-black', dv%in%c('Registered', 'Democrat', 'Republican'))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')),
+          coef = ifelse(dv %in% c('Democrat', 'Republican') & !state %in% pid.states, NA, coef),
+          se = ifelse(dv %in% c('Democrat', 'Republican') & !state %in% pid.states, NA, se))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, linetype = race, fill = race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dashed', 'dotdash', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.3,1)+
+   theme(axis.text.y=element_blank(), axis.title.y=element_blank(), 
+         strip.text.x = element_text(face='bold', size =14),strip.text.y = element_text(face='bold', size =14),
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank())+
+   facet_wrap(dv ~ ., nrow = 3)
+ )

> ggsave(filename = "figures/FigS24.pdf", width=9,height=5,
+ plot = ggplot(data = plt2[plt2$dv %in% c("Vote 2010", "Vote 2012", "Vote 2014", "Vote 2016"),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2010", "2012", "2014", "2016"))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> ggsave(filename = 'figures/FigS25.pdf', width = 9, height = 5, 
+ plot = data %>%
+   mutate(race=Hmisc::capitalize(race))%>%
+   filter(endog=='Vote 2008', grepl('Vote', dv))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   mutate( dv = paste(gsub('Vote ', '', dv),' Election')) %>%  
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, linetype = race, fill = race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dashed', 'dotdash', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.05,0.45)+
+   theme(axis.text.y=element_blank(), axis.title.y=element_blank(), 
+         strip.text.x = element_text(face='bold', size =14),strip.text.y = element_text(face='bold', size =14),
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank())+
+   facet_wrap(dv ~ ., nrow = 4)
+ )

> # Table 3, Figure S5-S8
> rm(list=ls())

> gc()
          used  (Mb) gc trigger   (Mb) limit (Mb)  max used   (Mb)
Ncells 3227525 172.4    4948840  264.3         NA   4948840  264.3
Vcells 5468136  41.8  133775839 1020.7      16384 209024557 1594.8

> source('primary_analysis_state_loop_other.R', echo = T,  max.deparse.length=10000)

> rm(list=ls())

> gc()
          used  (Mb) gc trigger  (Mb) limit (Mb)  max used   (Mb)
Ncells 3227899 172.4    4948840 264.3         NA   4948840  264.3
Vcells 5469732  41.8  107020672 816.6      16384 209024557 1594.8

> require(rddtools)

> require(AER)

> require(tidyverse)

> require(rdrobust)

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> for(state in states){
+   file = paste0('rdd_',state,'.Rdata')
+   load(file)
+   source('primary_analysis_rdd_other_elections.R')
+   print(state)
+   
+   
+ }
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"

> source('Tab3_FigS5_FigS6_FigS7_FigS8.R', echo = T,  max.deparse.length=10000)

> rm(list=ls())

> library(tidyverse)

> library(plyr)

> library(scales)

> library(dplyr)

> library(rmeta)

> library(xtable)

> library(stargazer)

Please cite as: 

 Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.3. https://CRAN.R-project.org/package=stargazer 


> # This script outputs:
>   # Figures 2, 3, 
>   # Tables 1, 2
> 
> 
> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> results = as.data.frame(matrix(nrow = 0, ncol = 7))

> colnames(results) = c("coef", "se", "race", "dv", "p value", "endog", "state")

> for(state in states){
+   f = paste0('results/results_',state,'_other_elections.Rdata')
+   
+   load(f)
+   holder = as.data.frame(matrix(nrow = 60, ncol = 7))
+   colnames(holder) = c("coef", "se", "race", "dv", "p value", "endog", "state")
+   
+   holder$coef = c(ivmod1_white$cace,  ivmod1_black$cace, ivmod1_hispanic$cace,
+                   ivmod2_white$cace,  ivmod2_black$cace, ivmod2_hispanic$cace,
+                   ivmod3_white$cace,  ivmod3_black$cace, ivmod3_hispanic$cace,
+                   ivmod4_white$cace,  ivmod4_black$cace, ivmod4_hispanic$cace,
+                   ivmod5_white$cace,  ivmod5_black$cace, ivmod5_hispanic$cace,
+                   ivmod6_white$cace,  ivmod6_black$cace, ivmod6_hispanic$cace,
+                   ivmod_rep_white$cace,  ivmod_rep_black$cace, ivmod_rep_hispanic$cace,
+                   ivmod7_white$cace,  ivmod7_black$cace, ivmod7_hispanic$cace,
+                   ivmod8_white$cace, ivmod8_black$cace, ivmod8_hispanic$cace,
+                   ivmod9_white$cace,  ivmod9_black$cace, ivmod9_hispanic$cace,
+                   ivmod10_white$cace,  ivmod10_black$cace, ivmod10_hispanic$cace,
+                   
+                   
+                   
+                   
+                   ivmod_04_1_white$cace,  ivmod_04_1_black$cace, ivmod_04_1_hispanic$cace,
+                   ivmod_04_2_white$cace,  ivmod_04_2_black$cace, ivmod_04_2_hispanic$cace,
+                   ivmod_04_3_white$cace,  ivmod_04_3_black$cace, ivmod_04_3_hispanic$cace,
+                   ivmod_04_4_white$cace,  ivmod_04_4_black$cace, ivmod_04_4_hispanic$cace,
+                   ivmod_04_5_white$cace, ivmod_04_5_black$cace, ivmod_04_5_hispanic$cace,
+                   ivmod_04_6_white$cace, ivmod_04_6_black$cace, ivmod_04_6_hispanic$cace,
+                   ivmod_04__rep_white$cace,  ivmod_04__rep_black$cace, ivmod_04__rep_hispanic$cace,
+                   ivmod_04_7_white$cace,  ivmod_04_7_black$cace, ivmod_04_7_hispanic$cace,
+                   ivmod_04_8_white$cace,  ivmod_04_8_black$cace, ivmod_04_8_hispanic$cace
+                   
+                   
+                   
+                   
+   )
+   
+   holder$se = c(ivmod1_white$se,  ivmod1_black$se, ivmod1_hispanic$se,
+                 ivmod2_white$se,  ivmod2_black$se, ivmod2_hispanic$se,
+                 ivmod3_white$se,  ivmod3_black$se, ivmod3_hispanic$se,
+                 ivmod4_white$se,  ivmod4_black$se, ivmod4_hispanic$se,
+                 ivmod5_white$se, ivmod5_black$se, ivmod5_hispanic$se,
+                 ivmod6_white$se,  ivmod6_black$se, ivmod6_hispanic$se,
+                 ivmod_rep_white$se,  ivmod_rep_black$se, ivmod_rep_hispanic$se,
+                 ivmod7_white$se,  ivmod7_black$se, ivmod7_hispanic$se,
+                 ivmod8_white$se, ivmod8_black$se, ivmod8_hispanic$se,
+                 ivmod9_white$se, ivmod9_black$se, ivmod9_hispanic$se,
+                 ivmod10_white$se,  ivmod10_black$se, ivmod10_hispanic$se,
+                 
+                 
+                 
+                 
+                 ivmod_04_1_white$se, ivmod_04_1_black$se, ivmod_04_1_hispanic$se,
+                 ivmod_04_2_white$se,  ivmod_04_2_black$se, ivmod_04_2_hispanic$se,
+                 ivmod_04_3_white$se,  ivmod_04_3_black$se, ivmod_04_3_hispanic$se,
+                 ivmod_04_4_white$se,  ivmod_04_4_black$se, ivmod_04_4_hispanic$se,
+                 ivmod_04_5_white$se,  ivmod_04_5_black$se, ivmod_04_5_hispanic$se,
+                 ivmod_04_6_white$se,  ivmod_04_6_black$se, ivmod_04_6_hispanic$se,
+                 ivmod_04__rep_white$se,  ivmod_04__rep_black$se, ivmod_04__rep_hispanic$se,
+                 ivmod_04_7_white$se,  ivmod_04_7_black$se, ivmod_04_7_hispanic$se,
+                 ivmod_04_8_white$se,  ivmod_04_8_black$se, ivmod_04_8_hispanic$se
+                 
+                 
+                 
+                 
+                 
+                 
+   )
+   
+   holder$`p value` = c(ivmod1_white$summary$coefficients[2,4],  ivmod1_black$summary$coefficients[2,4], ivmod1_hispanic$summary$coefficients[2,4],
+                        ivmod2_white$summary$coefficients[2,4],  ivmod2_black$summary$coefficients[2,4], ivmod2_hispanic$summary$coefficients[2,4],
+                        ivmod3_white$summary$coefficients[2,4],  ivmod3_black$summary$coefficients[2,4], ivmod3_hispanic$summary$coefficients[2,4],
+                        ivmod4_white$summary$coefficients[2,4],  ivmod4_black$summary$coefficients[2,4], ivmod4_hispanic$summary$coefficients[2,4],
+                        ivmod5_white$summary$coefficients[2,4],  ivmod5_black$summary$coefficients[2,4], ivmod5_hispanic$summary$coefficients[2,4],
+                        ivmod6_white$summary$coefficients[2,4],  ivmod6_black$summary$coefficients[2,4], ivmod6_hispanic$summary$coefficients[2,4],
+                        ivmod_rep_white$summary$coefficients[2,4],  ivmod_rep_black$summary$coefficients[2,4], ivmod_rep_hispanic$summary$coefficients[2,4],
+                        ivmod7_white$summary$coefficients[2,4],  ivmod7_black$summary$coefficients[2,4], ivmod7_hispanic$summary$coefficients[2,4],
+                        ivmod8_white$summary$coefficients[2,4],  ivmod8_black$summary$coefficients[2,4], ivmod8_hispanic$summary$coefficients[2,4],
+                        ivmod9_white$summary$coefficients[2,4],  ivmod9_black$summary$coefficients[2,4], ivmod9_hispanic$summary$coefficients[2,4],
+                        ivmod10_white$summary$coefficients[2,4], ivmod10_black$summary$coefficients[2,4], ivmod10_hispanic$summary$coefficients[2,4],
+                        
+                        
+                        
+                        
+                        ivmod_04_1_white$summary$coefficients[2,4], ivmod_04_1_black$summary$coefficients[2,4], ivmod_04_1_hispanic$summary$coefficients[2,4],
+                        ivmod_04_2_white$summary$coefficients[2,4], ivmod_04_2_black$summary$coefficients[2,4], ivmod_04_2_hispanic$summary$coefficients[2,4],
+                        ivmod_04_3_white$summary$coefficients[2,4],  ivmod_04_3_black$summary$coefficients[2,4], ivmod_04_3_hispanic$summary$coefficients[2,4],
+                        ivmod_04_4_white$summary$coefficients[2,4],  ivmod_04_4_black$summary$coefficients[2,4], ivmod_04_4_hispanic$summary$coefficients[2,4],
+                        ivmod_04_5_white$summary$coefficients[2,4],  ivmod_04_5_black$summary$coefficients[2,4], ivmod_04_5_hispanic$summary$coefficients[2,4],
+                        ivmod_04_6_white$summary$coefficients[2,4],  ivmod_04_6_black$summary$coefficients[2,4], ivmod_04_6_hispanic$summary$coefficients[2,4],
+                        ivmod_04__rep_white$summary$coefficients[2,4], ivmod_04__rep_black$summary$coefficients[2,4], ivmod_04__rep_hispanic$summary$coefficients[2,4],
+                        ivmod_04_7_white$summary$coefficients[2,4],  ivmod_04_7_black$summary$coefficients[2,4], ivmod_04_7_hispanic$summary$coefficients[2,4],
+                        ivmod_04_8_white$summary$coefficients[2,4],  ivmod_04_8_black$summary$coefficients[2,4], ivmod_04_8_hispanic$summary$coefficients[2,4]
+                        
+                        
+                        
+                        
+                        
+                        
+   )
+   
+   ##############
+   holder$race = c(rep(c("white", "black", "hispanic"), 20))
+   
+   holder$dv = c(c(rep("Vote 2016", 3),
+                   rep("Vote 2014", 3),
+                   rep("Vote 2012", 3),
+                   rep("Vote 2010", 3),
+                   rep("Democrat", 3),
+                   rep("Registered", 3),
+                   rep("Republican", 3)),
+                 rep("Vote 2008", 3),
+                 rep("Vote 2006", 3),
+                 rep("Vote 2004", 3),
+                 rep("Vote 2002", 3),
+                 
+                 c(rep("Vote 2016", 3),
+                   rep("Vote 2014", 3),
+                   rep("Vote 2012", 3),
+                   rep("Vote 2010", 3),
+                   rep("Democrat", 3),
+                   rep("Registered", 3),
+                   rep("Republican", 3)),
+                 rep("Vote 2008", 3),
+                 rep("Vote 2006", 3)
+                 
+   )
+   
+   
+   holder$endog = c(rep("Vote 2000", 11*3),
+                    rep("Vote 2004", 9*3))
+   holder$state = state
+   
+   
+   results = rbind(results, holder)
+   
+   print(f); print(nrow(results))
+ }
[1] "results/results_al_other_elections.Rdata"
[1] 60
[1] "results/results_ar_other_elections.Rdata"
[1] 120
[1] "results/results_ca_other_elections.Rdata"
[1] 180
[1] "results/results_ct_other_elections.Rdata"
[1] 240
[1] "results/results_fl_other_elections.Rdata"
[1] 300
[1] "results/results_il_other_elections.Rdata"
[1] 360
[1] "results/results_in_other_elections.Rdata"
[1] 420
[1] "results/results_ks_other_elections.Rdata"
[1] 480
[1] "results/results_ky_other_elections.Rdata"
[1] 540
[1] "results/results_ma_other_elections.Rdata"
[1] 600
[1] "results/results_md_other_elections.Rdata"
[1] 660
[1] "results/results_mo_other_elections.Rdata"
[1] 720
[1] "results/results_ne_other_elections.Rdata"
[1] 780
[1] "results/results_nv_other_elections.Rdata"
[1] 840
[1] "results/results_ny_other_elections.Rdata"
[1] 900
[1] "results/results_oh_other_elections.Rdata"
[1] 960
[1] "results/results_or_other_elections.Rdata"
[1] 1020
[1] "results/results_pa_other_elections.Rdata"
[1] 1080
[1] "results/results_ri_other_elections.Rdata"
[1] 1140
[1] "results/results_sc_other_elections.Rdata"
[1] 1200
[1] "results/results_tn_other_elections.Rdata"
[1] 1260
[1] "results/results_tx_other_elections.Rdata"
[1] 1320
[1] "results/results_va_other_elections.Rdata"
[1] 1380
[1] "results/results_wa_other_elections.Rdata"
[1] 1440
[1] "results/results_wv_other_elections.Rdata"
[1] 1500

> rm(list=ls()[grepl('mod',ls())])

> gc()
          used  (Mb) gc trigger   (Mb) limit (Mb)  max used   (Mb)
Ncells 3239125 173.0    4948840  264.3         NA   4948840  264.3
Vcells 5544825  42.4  283583405 2163.6      16384 382317008 2916.9

> # save state-level results for later modeling
> write_csv(results,'results/other_elections_state_results.csv')
[1mwrote[0m [32m718.00B[0m in [36m 0s[0m, [32m177.15MB/s[0m                                                                                                                                    [1mwrote[0m [32m1.00TB[0m in [36m 0s[0m, [32m71.53TB/s[0m                                                                                                                                    
> data = read_csv("results/main_state_results.csv")%>%
+   bind_rows(read_csv("results/other_elections_state_results.csv"))%>%
+   select(coef, se, race, dv, endog, state)%>%
+   filter(grepl('Vote', dv))%>%
+   mutate(`2008 Election` = as.numeric(endog=='Vote 2008'),
+          black = as.numeric(race=='black'),
+          white = as.numeric(race=='white'),
+          hispanic = as.numeric(race=='hispanic'),
+          w= 1/(se^2),
+          dist = as.numeric(gsub('Vote ', '',dv))- as.numeric(gsub('Vote ', '',endog)),
+          presidential = as.numeric(dv %in% c('Vote 2004', 'Vote 2008', 'Vote 2012', 'Vote 2016')),
+          dv.age = as.numeric(gsub('Vote ', '',dv)),
+          ev.age = as.numeric(gsub('Vote ', '',endog)) )
[1mindexing[0m [34mmain_state_results.csv[0m [================================================================================] [32m38.03GB/s[0m, eta: [36m 0s[0m                                                                                                                                                                         Rows: 900 Columns: 7
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (4): race, dv, endog, state
dbl (3): coef, se, p value

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
[1mindexing[0m [34mother_elections_state_results.csv[0m [=====================================================================] [32m25.35GB/s[0m, eta: [36m 0s[0m                                                                                                                                                                         Rows: 1500 Columns: 7
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (4): race, dv, endog, state
dbl (3): coef, se, p value

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

> # black mobilization effect in absolute terms'
> library(fixest)

Attaching package: ‘fixest’

The following object is masked from ‘package:scales’:

    pvalue

The following object is masked from ‘package:np’:

    se


> mod1=feols(coef ~ `2008 Election`+ presidential + dv.age+ev.age | state, data = data %>% filter(black==1), weights = data$w[data$black==1], cluster = ~ev.age)
NOTE: 36 observations removed because of NA values (LHS: 36, Weights: 36).

> mod2=feols(coef ~ `2008 Election`*black+ dv.age+ev.age | state, data = data, weights = data$w, cluster = ~ev.age)
NOTE: 109 observations removed because of NA values (LHS: 109, Weights: 109).

> mod1_nw=feols(coef ~ `2008 Election`+ presidential + dv.age+ev.age | state, data = data %>% filter(black==1), cluster = ~ev.age)
NOTE: 36 observations removed because of NA values (LHS: 36).

> mod2_nw=feols(coef ~ `2008 Election`*black+ dv.age+ev.age | state, data = data, cluster = ~ev.age)
NOTE: 109 observations removed because of NA values (LHS: 109).

> etable(mod1,mod1_nw,mod2,mod2_nw, digits =3, tex = T, fitstat = c('n','r2','wr2'), digits.stats=3,
+        style.tex = style.tex("aer"), file = 'tables/Tab3.tex', replace = T)

> # all races
> ggsave(filename = 'figures/FigS6.pdf', width = 9, height = 5, 
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race))%>%
+   filter(endog=='Vote 2004', race!='Non-black', grepl('Vote', dv))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, fill = race,linetype=race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dotted', 'dashed', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.1,1)+
+   ylab('Density')+
+   theme(legend.title=element_blank(), legend.position = 'bottom', legend.spacing.x = unit(.25, 'cm'),
+         axis.title.y=element_blank(), axis.text.y=element_blank(),
+         axis.ticks.y=element_blank())+  facet_wrap(dv ~ ., nrow = 4)
+ )

> ggsave(filename = 'Figures/FigS8.pdf', width = 9, height = 5, 
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race))%>%
+   filter(endog=='Vote 2000', race!='Non-black', grepl('Vote', dv))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se), group = race, fill = race, linetype = race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   xlim(-0.75,1.75)+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dotted', 'dashed', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   theme(legend.title=element_blank(), legend.position = 'bottom', legend.spacing.x = unit(.25, 'cm'),
+         axis.title.y=element_blank(), axis.text.y=element_blank(),
+         axis.ticks.y=element_blank())+  facet_wrap(dv ~ ., nrow = 4)
+ )

> ### Weighted Average of State CACEs
> 
> predictions_white = as.data.frame(matrix(NA, ncol = 5))

> predictions_black = as.data.frame(matrix(NA, ncol = 5))

> predictions_hispanic = as.data.frame(matrix(NA, ncol = 5))

> colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_black) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_hispanic) = c("ev", "dv", "coef", "se", "race")

> predictions_white$race = "white"

> predictions_black$race = "black"

> predictions_hispanic$race = "hispanic"

> data = results

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white"  & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j]])
+       predictions_black = rbind(predictions_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_black$est, preds_black$se, "black"))
+       
+       preds_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic"  & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$dv == unique(data$dv)[j]])
+       predictions_hispanic = rbind(predictions_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_hispanic$est, preds_hispanic$se, "hispanic"))
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_white, predictions_black, predictions_hispanic)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> plt = meta_plot%>%filter(ev == "Vote 2004" & race != "all" & !is.na(race))%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')))

> ggsave(filename = "figures/FigS5.pdf", width=9,height=5,
+ plot = ggplot(data =plt[grepl('Vote', plt$dv),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2004 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2006", "2008", "2010", "2012", '2014', '2016'))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> plt = meta_plot%>%filter(ev == "Vote 2000" & race != "all" & !is.na(race))%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')))

> ggsave(filename = "figures/FigS7.pdf", width=9,height=5,
+ plot = ggplot(data = plt[grepl('Vote', plt$dv),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2000 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c('2002', '2004', "2006", "2008", "2010", "2012", '2014', '2016'))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> # Figure S1-S8 already created in prior scripts
> 
> # Figure S9
> rm(list=ls())

> gc()
          used  (Mb) gc trigger   (Mb) limit (Mb)  max used   (Mb)
Ncells 3382923 180.7    4948840  264.3         NA   4948840  264.3
Vcells 5802848  44.3  226866724 1730.9      16384 382317008 2916.9

> source('FigS9.R', echo = T,  max.deparse.length=10000)

> rm(list=ls())

> library(tidyverse)

> library(plyr)

> library(scales)

> library(dplyr)

> library(rmeta)

> library(xtable)

> library(stargazer)

> library(data.table)
data.table 1.14.2 using 1 threads (see ?getDTthreads).  Latest news: r-datatable.com
**********
This installation of data.table has not detected OpenMP support. It should still work but in single-threaded mode.
This is a Mac. Please read https://mac.r-project.org/openmp/. Please engage with Apple and ask them for support. Check r-datatable.com for updates, and our Mac instructions here: https://github.com/Rdatatable/data.table/wiki/Installation. After several years of many reports of installation problems on Mac, it's time to gingerly point out that there have been no similar problems on Windows or Linux.
**********

Attaching package: ‘data.table’

The following objects are masked from ‘package:dplyr’:

    between, first, last

The following object is masked from ‘package:purrr’:

    transpose

The following object is masked from ‘package:tictoc’:

    shift


> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> load("rdd_fl09.Rdata")

> fl09=data

> load("rdd_fl.Rdata")

> fl09=as.data.table(fl09)

> data=as.data.table(data)

> fl09$dob = as.character(fl09$dob)

> data$dob=as.character(data$dob)

> fl09[is.na(vote2008_white), vote2008_white:=0]

> fl09[is.na(vote2008_black), vote2008_black:=0]

> fl09[is.na(vote2008_hispanic), vote2008_hispanic:=0]

> out = merge(data, fl09[,c('dob','vote2008_hispanic', 'vote2008_white', 'vote2008_black')],
+             all.x=T, by = 'dob')

> data = as.data.frame(out)

> rm(out,fl09)

> data$forcing = as.integer(as.Date("1990-11-04"))- as.integer(as.Date(data$dob))

> data$Cutoff08 = ifelse(data$forcing >= 0, 1, 0)

> ################# DV: Vote 2016 ########################
> 
> ivmod1_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_white", 
+                                             downstream_voted = "vote.gen2016_white", downstream_lag = "lag2016_white", bandwidth = 365, state.abbrev=NULL)

> ivmod1_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_black", 
+                                             downstream_voted = "vote.gen2016_black", downstream_lag = "lag2016_black", bandwidth = 365, state.abbrev=NULL)

> ivmod1_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_hispanic", 
+                                                downstream_voted = "vote.gen2016_hispanic", downstream_lag = "lag2016_hispanic", bandwidth = 365, state.abbrev=NULL)

> ##################### DV: Vote 2014 ##########################
> 
> 
> ivmod2_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_white", 
+                                             downstream_voted = "vote.gen2014_white", downstream_lag = "lag2014_white", bandwidth = 365, state.abbrev=NULL)

> ivmod2_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_black", 
+                                             downstream_voted = "vote.gen2014_black", downstream_lag = "lag2014_black", bandwidth = 365, state.abbrev=NULL)

> ivmod2_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_hispanic", 
+                                                downstream_voted = "vote.gen2014_hispanic", downstream_lag = "lag2014_hispanic", bandwidth = 365, state.abbrev=NULL)

> ##################### DV: Vote 2012 ##########################
> 
> ivmod3_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_white", 
+                                             downstream_voted = "vote.gen2012_white", downstream_lag = "lag2012_white", bandwidth = 365, state.abbrev=NULL)

> ivmod3_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_black", 
+                                             downstream_voted = "vote.gen2012_black", downstream_lag = "lag2012_black", bandwidth = 365, state.abbrev=NULL)

> ivmod3_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_hispanic", 
+                                                downstream_voted = "vote.gen2012_hispanic", downstream_lag = "lag2012_hispanic", bandwidth = 365, state.abbrev=NULL)

> ##################### DV: Vote 2010 ##########################
> 
> 
> ivmod4_white = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_white", 
+                                             downstream_voted = "vote.gen2010_white", downstream_lag = "lag2010_white", bandwidth = 365, state.abbrev=NULL)

> ivmod4_black = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_black", 
+                                             downstream_voted = "vote.gen2010_black", downstream_lag = "lag2010_black", bandwidth = 365, state.abbrev=NULL)

> ivmod4_hispanic = state.cace.estimator.primary(data = data, upstream_days = "forcing", upstream_treat = "Cutoff08", upstream_voted = "vote2008_hispanic", 
+                                                downstream_voted = "vote.gen2010_hispanic", downstream_lag = "lag2010_hispanic", bandwidth = 365, state.abbrev=NULL)

> rm(data)

> save.image(file = "results/results_fl09.Rdata")

> #########
> rm(list=ls())

> states = c('fl', 'fl09')

> results = as.data.frame(matrix(nrow = 0, ncol = 7))

> colnames(results) = c("coef", "se", "race", "dv", "p value", "endog", "state")

> for(state in states){
+   f = paste0('results/results_',state,'.Rdata')
+   load(f)
+   holder = as.data.frame(matrix(nrow = 12, ncol = 7))
+   colnames(holder) = c("coef", "se", "race", "dv", "p value", "endog", "state")
+   
+   holder$coef = c(ivmod1_white$cace, ivmod1_black$cace, ivmod1_hispanic$cace,
+                   ivmod2_white$cace,  ivmod2_black$cace, ivmod2_hispanic$cace,
+                   ivmod3_white$cace,  ivmod3_black$cace, ivmod3_hispanic$cace,
+                   ivmod4_white$cace,  ivmod4_black$cace, ivmod4_hispanic$cace
+                   
+                   
+                   
+                   
+                   
+                   
+                   
+                   
+                   
+   )
+   
+   holder$se = c(ivmod1_white$se,  ivmod1_black$se, ivmod1_hispanic$se,
+                 ivmod2_white$se,  ivmod2_black$se, ivmod2_hispanic$se,
+                 ivmod3_white$se,  ivmod3_black$se, ivmod3_hispanic$se,
+                 ivmod4_white$se,  ivmod4_black$se, ivmod4_hispanic$se
+                 
+                 
+                 
+                 
+                 
+                 
+   )
+   
+   holder$`p value` = c(ivmod1_white$summary$coefficients[2,4],  ivmod1_black$summary$coefficients[2,4], ivmod1_hispanic$summary$coefficients[2,4],
+                        ivmod2_white$summary$coefficients[2,4],  ivmod2_black$summary$coefficients[2,4], ivmod2_hispanic$summary$coefficients[2,4],
+                        ivmod3_white$summary$coefficients[2,4],  ivmod3_black$summary$coefficients[2,4], ivmod3_hispanic$summary$coefficients[2,4],
+                        ivmod4_white$summary$coefficients[2,4],  ivmod4_black$summary$coefficients[2,4], ivmod4_hispanic$summary$coefficients[2,4]
+                        
+                        
+                        
+                        
+                        
+   )
+   ############itt
+   
+   ##############
+   holder$race = c(rep(c("white", "black", "hispanic"), 4))
+   
+   holder$dv = c(c(rep("Vote 2016", 3),
+                   rep("Vote 2014", 3),
+                   rep("Vote 2012", 3),
+                   rep("Vote 2010", 3)))
+   
+   
+   holder$endog = c(rep("Vote 2008", 12))
+   holder$state = state
+   
+   
+   results = rbind(results, holder)
+   
+   print(f); print(nrow(results))
+ }
[1] "results/results_fl.Rdata"
[1] 12
[1] "results/results_fl09.Rdata"
[1] 24

> plt = results%>%filter(endog == "Vote 2008" & race %in% c('white', 'hispanic', 'black') & !is.na(race) )%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')),
+          state = ifelse(state=='fl09', 'Using 2009 Voterfile', 'Main Results'))

> ggsave(filename = "figures/FigS9.pdf", width=9,height=5,
+ ggplot(data = plt[plt$dv %in% c("Vote 2010", "Vote 2012", "Vote 2014", "Vote 2016"),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+ 
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2010", "2012", "2014", "2016"))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   facet_wrap(state~., nrow = 3)
+ )

> # figure S10 already created in prior script
> 
> 
> # Figure S11 and Figure S12
> rm(list=ls())

> gc()
          used  (Mb) gc trigger   (Mb) limit (Mb)  max used   (Mb)
Ncells 3421899 182.8    6242985  333.5         NA   4948840  264.3
Vcells 5895467  45.0  181493380 1384.7      16384 382317008 2916.9

> source('primary_analysis_state_loop_bw.R', echo = T,  max.deparse.length=10000)

> require(rddtools)

> require(AER)

> require(tidyverse)

> require(rdrobust)

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> for(state in states){
+     for(bw in seq(14, 352,  by = 14)){
+       file = paste0('rdd_',state,'.Rdata')
+     load(file)
+     source('primary_analysis_rdd_bw.R')
+       print(bw)
+     }
+     print(state)
+ }
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "al"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ar"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ca"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ct"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "fl"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "il"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "in"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ks"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ky"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ma"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "md"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "mo"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ne"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "nv"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ny"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "oh"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "or"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "pa"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "ri"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "sc"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "tn"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "tx"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "va"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "wa"
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350
[1] "wv"

> source('FigS11_FigS12.R', echo = T,  max.deparse.length=10000)

> rm(list=ls())

> library(tidyverse)

> library(BBmisc)

Attaching package: ‘BBmisc’

The following objects are masked from ‘package:dplyr’:

    coalesce, collapse

The following object is masked from ‘package:Hmisc’:

    %nin%

The following object is masked from ‘package:base’:

    isFALSE


> library(data.table)

> library(rmeta)

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> l = rbindlist(lapply(seq(14, 352,  by = 14), FUN = function(kt){
+ output = list.files('results')[grepl(paste0("bw",kt,".Rdata"), list.files('results'))  ]
+ 
+ main_results = as.data.frame(matrix(nrow = 0, ncol =6))
+ colnames(main_results) = c("coef", "se", "race", "dv",  "endog", "state")
+ 
+ 
+ 
+ for(check in output){
+   load(paste0("results/", check))
+   results = as.data.frame(matrix(nrow = 21, ncol = 6))
+   colnames(results) = c("coef", "se", "race", "dv", "endog", "state")
+   
+   ## recode if error
+   
+   # white
+   if(is.error(ivmod1_white)){
+     ivmod1_white = list()
+     ivmod1_white$cace=NA
+     ivmod1_white$se=NA
+   }
+   
+   if(is.error(ivmod2_white)){
+     ivmod2_white = list()
+     ivmod2_white$cace=NA
+     ivmod2_white$se=NA
+   }
+   
+   if(is.error(ivmod5_white)){
+     ivmod5_white = list()
+     ivmod5_white$cace=NA
+     ivmod5_white$se=NA
+   }
+   
+   if(is.error(ivmod6_white)){
+     ivmod6_white = list()
+     ivmod6_white$cace=NA
+     ivmod6_white$se=NA
+   }
+   
+   if(is.error(ivmod_rep_white)){
+     ivmod_rep_white = list()
+     ivmod_rep_white$cace=NA
+     ivmod_rep_white$se=NA
+   }
+   
+ 
+   #black
+   if(is.error(ivmod1_black)){
+     ivmod1_black = list()
+     ivmod1_black$cace=NA
+     ivmod1_black$se=NA
+   }
+   
+   if(is.error(ivmod2_black)){
+     ivmod2_black = list()
+     ivmod2_black$cace=NA
+     ivmod2_black$se=NA
+   }
+   
+   if(is.error(ivmod5_black)){
+     ivmod5_black = list()
+     ivmod5_black$cace=NA
+     ivmod5_black$se=NA
+   }
+   
+   if(is.error(ivmod6_black)){
+     ivmod6_black = list()
+     ivmod6_black$cace=NA
+     ivmod6_black$se=NA
+   }
+   
+   if(is.error(ivmod_rep_black)){
+     ivmod_rep_black = list()
+     ivmod_rep_black$cace=NA
+     ivmod_rep_black$se=NA
+   }
+   
+ 
+   
+   #hispanic
+   if(is.error(ivmod1_hispanic)){
+     ivmod1_hispanic = list()
+     ivmod1_hispanic$cace=NA
+     ivmod1_hispanic$se=NA
+   }
+   
+   if(is.error(ivmod2_hispanic)){
+     ivmod2_hispanic = list()
+     ivmod2_hispanic$cace=NA
+     ivmod2_hispanic$se=NA
+   }
+   
+   if(is.error(ivmod5_hispanic)){
+     ivmod5_hispanic = list()
+     ivmod5_hispanic$cace=NA
+     ivmod5_hispanic$se=NA
+   }
+   
+   if(is.error(ivmod6_hispanic)){
+     ivmod6_hispanic = list()
+     ivmod6_hispanic$cace=NA
+     ivmod6_hispanic$se=NA
+   }
+   
+   if(is.error(ivmod_rep_hispanic)){
+     ivmod_rep_hispanic = list()
+     ivmod_rep_hispanic$cace=NA
+     ivmod_rep_hispanic$se=NA
+   }
+   
+ 
+   ##
+   results$coef = c(ivmod1_white$cace, ivmod1_black$cace, ivmod1_hispanic$cace,
+                    ivmod2_white$cace, ivmod2_black$cace, ivmod2_hispanic$cace,
+                    ivmod3_white$cace, ivmod3_black$cace, ivmod3_hispanic$cace,
+                    ivmod4_white$cace, ivmod4_black$cace, ivmod4_hispanic$cace,
+                    
+                    ivmod5_white$cace, ivmod5_black$cace, ivmod5_hispanic$cace,
+                    ivmod6_white$cace, ivmod6_black$cace, ivmod6_hispanic$cace,
+                    ivmod_rep_white$cace, ivmod_rep_black$cace, ivmod_rep_hispanic$cace)
+   
+   results$se = c(  ivmod1_white$se, ivmod1_black$se, ivmod1_hispanic$se,
+                    ivmod2_white$se, ivmod2_black$se, ivmod2_hispanic$se,
+                    ivmod3_white$se, ivmod3_black$se, ivmod3_hispanic$se,
+                    ivmod4_white$se, ivmod4_black$se, ivmod4_hispanic$se,
+                    
+                     ivmod5_white$se, ivmod5_black$se, ivmod5_hispanic$se,
+                    ivmod6_white$se, ivmod6_black$se, ivmod6_hispanic$se,
+                    ivmod_rep_white$se, ivmod_rep_black$se, ivmod_rep_hispanic$se)
+   
+ 
+    ##############
+   results$race = c(rep(c("white", "black", "hispanic"), 7))
+   
+   results$dv = c(c(rep("Vote 2016", 3),
+                  rep("Vote 2014", 3),
+                  rep("Vote 2012", 3),
+                  rep("Vote 2010", 3),
+                  rep("Democrat", 3),
+                  rep("Registered", 3),
+                  rep("Republican", 3)))
+   
+   
+   results$endog = c(rep("Vote 2008", 3*7))
+   results$state = sub(as.character(kt),"",sub("_bw","",sub("results_","", sub(".Rdata", "", check))))
+   results$bw = kt
+   
+   main_results = rbind(main_results, results)
+   rm(list=ls(pattern = "mod"))
+   
+ }
+ 
+ 
+ 
+ 
+ 
+ print(kt)
+ return(main_results)
+ }))
[1] 14
[1] 28
[1] 42
[1] 56
[1] 70
[1] 84
[1] 98
[1] 112
[1] 126
[1] 140
[1] 154
[1] 168
[1] 182
[1] 196
[1] 210
[1] 224
[1] 238
[1] 252
[1] 266
[1] 280
[1] 294
[1] 308
[1] 322
[1] 336
[1] 350

> m = rbindlist(lapply(seq(14, 352,  by = 14),FUN=function(kt){
+   data = l %>%
+     filter(bw == kt & !is.na(coef) & !is.na(se))
+ predictions_white = as.data.frame(matrix(NA, ncol = 5))
+ predictions_black = as.data.frame(matrix(NA, ncol = 5))
+ predictions_hispanic = as.data.frame(matrix(NA, ncol = 5))
+ colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")
+ colnames(predictions_black) = c("ev", "dv", "coef", "se", "race")
+ colnames(predictions_hispanic) = c("ev", "dv", "coef", "se", "race")
+ predictions_white$race = "white"
+ predictions_black$race = "black"
+ predictions_hispanic$race = "hispanic"
+ 
+ for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+   
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white"& data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "black"& data$dv == unique(data$dv)[j]])
+       predictions_black = rbind(predictions_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_black$est, preds_black$se, "black"))
+       
+       preds_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic"& data$dv == unique(data$dv)[j]])
+       predictions_hispanic = rbind(predictions_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_hispanic$est, preds_hispanic$se, "hispanic"))
+     }
+     
+   }
+   
+ }
+ meta_plot=rbind(predictions_white, predictions_black, predictions_hispanic)
+ for(i in 3:(ncol(meta_plot)-1)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }
+ meta_plot$bw=kt
+ return(meta_plot)
+ }))

> ggsave(plot=ggplot(data = m %>%
+                      filter(grepl('Vote',dv)), aes(x=bw, y=coef, group = race), color = "black") +
+          geom_line(aes(linetype=race))+
+          geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+          geom_ribbon(aes(ymin = coef-1.96*se, ymax=coef+1.96*se), alpha = .25)+
+          xlab("Bandwidth")+
+          ylab("CACE")+
+          theme_bw()+
+          theme(text = element_text(size=15), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),legend.position="bottom", 
+                legend.title = element_blank(),
+                legend.text=element_text(size=15), axis.text = element_text(size = 14),
+                legend.key.width=unit(3,"line")) +
+          facet_wrap(~dv), 
+        filename = "figures/FigS11.pdf", dpi = 300, width = 6, height = 6, units = 'in')

> ggsave(plot=ggplot(data = m %>%
+                      filter(!grepl('Vote',dv) & !is.na(dv)), aes(x=bw, y=coef, group = race), color = "black") +
+          geom_line(aes(linetype=race))+
+          geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+          geom_ribbon(aes(ymin = coef-1.96*se, ymax=coef+1.96*se), alpha = .25)+
+          xlab("Bandwidth")+
+          ylab("CACE")+
+          theme_bw()+
+          theme(text = element_text(size=15), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),legend.position="bottom", 
+                legend.title = element_blank(),
+                legend.text=element_text(size=15), axis.text = element_text(size = 14),
+                legend.key.width=unit(3,"line")) +
+          facet_wrap(~dv), 
+        filename = "figures/FigS12.pdf", dpi = 300, width = 6, height = 3, units = 'in')

> # Figures S13-S19
> rm(list=ls())

> gc()
          used  (Mb) gc trigger  (Mb) limit (Mb)  max used   (Mb)
Ncells 3992957 213.3    6242985 333.5         NA   6242985  333.5
Vcells 7713245  58.9   61460341 469.0      16384 382317008 2916.9

> source('primary_analysis_state_loop_specifications.R', echo = T,  max.deparse.length=10000)

> require(rddtools)

> require(AER)

> require(tidyverse)

> require(rdrobust)

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> for(p in 0:3){
+ for(state in states){
+   file = paste0('rdd_',state,'.Rdata')
+     load(file)
+     source('primary_analysis_rdd_specifications.R')
+     print(state)
+   
+ 
+ }
+   print(p)
+ }
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"
[1] 0
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"
[1] 1
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"
[1] 2
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"
[1] 3

> source('FigS13_FigS14_FigS15_FigS16_FigS17_FigS18_FigS19.R', echo = T, max.deparse.length=10000)

> require(tidyverse)

> require(dplyr)

> files = list.files("results")[grepl("lag", list.files("results"))]

> results_df = as.data.frame(matrix(nrow = 0, ncol = 8))

> colnames(results_df) = c("coef", "se", "race", "dv", "endog", "state", "specification", "lag")

> for(ob in files){
+   load(paste0("results/", ob))
+   holder = as.data.frame(matrix(nrow = 21, ncol = 8))
+   colnames(holder) = c("coef", "se", "race", "dv", "endog", "state", "specification", "lag")
+ 
+   holder$coef = c(
+               
+                    
+                    
+                    ivmod1_white$cace, ivmod1_black$cace, ivmod1_hispanic$cace,
+                     ivmod2_white$cace, ivmod2_black$cace, ivmod2_hispanic$cace,
+                    ivmod3_white$cace, ivmod3_black$cace, ivmod3_hispanic$cace,
+                    ivmod4_white$cace, ivmod4_black$cace, ivmod4_hispanic$cace,
+                    ivmod5_white$cace, ivmod5_black$cace, ivmod5_hispanic$cace,
+                    ivmod6_white$cace, ivmod6_black$cace, ivmod6_hispanic$cace,
+                     ivmod_rep_white$cace, ivmod_rep_black$cace, ivmod_rep_hispanic$cace
+                    
+                    
+                    
+                    
+                    )
+   
+   holder$se = c(
+                  ivmod1_white$se, ivmod1_black$se, ivmod1_hispanic$se,
+                   ivmod2_white$se, ivmod2_black$se, ivmod2_hispanic$se,
+                  ivmod3_white$se, ivmod3_black$se, ivmod3_hispanic$se,
+                  ivmod4_white$se, ivmod4_black$se, ivmod4_hispanic$se,
+                  ivmod5_white$se, ivmod5_black$se, ivmod5_hispanic$se,
+                  ivmod6_white$se, ivmod6_black$se, ivmod6_hispanic$se,
+                  ivmod_rep_white$se, ivmod_rep_black$se, ivmod_rep_hispanic$se
+                  
+   )
+ 
+  
+   ##############
+   holder$race = c(rep(c("white", "black", "hispanic"), 7))
+   
+   holder$dv = c(rep(c(rep("Vote 2016", 3),
+                  rep("Vote 2014", 3),
+                  rep("Vote 2012", 3),
+                 rep("Vote 2010", 3),
+                  rep("Democrat", 3),
+                  rep("Registered", 3),
+                  rep("Republican", 3))
+                  
+                  ))
+   
+   
+   holder$endog = "2008"
+   
+   holder$specification = str_extract(ob, "[[:digit:]]+")
+   
+   holder$lag = ifelse(grepl("nolag", ob), "nolag", "lag")
+                     
+   holder$state = substr(ob,9,10)
+   
+   
+   results_df = rbind(results_df, holder)
+   
+   print(ob)
+ }
[1] "results_al_specification_0lag.Rdata"
[1] "results_al_specification_0nolag.Rdata"
[1] "results_al_specification_1lag.Rdata"
[1] "results_al_specification_1nolag.Rdata"
[1] "results_al_specification_2lag.Rdata"
[1] "results_al_specification_2nolag.Rdata"
[1] "results_al_specification_3lag.Rdata"
[1] "results_al_specification_3nolag.Rdata"
[1] "results_ar_specification_0lag.Rdata"
[1] "results_ar_specification_0nolag.Rdata"
[1] "results_ar_specification_1lag.Rdata"
[1] "results_ar_specification_1nolag.Rdata"
[1] "results_ar_specification_2lag.Rdata"
[1] "results_ar_specification_2nolag.Rdata"
[1] "results_ar_specification_3lag.Rdata"
[1] "results_ar_specification_3nolag.Rdata"
[1] "results_ca_specification_0lag.Rdata"
[1] "results_ca_specification_0nolag.Rdata"
[1] "results_ca_specification_1lag.Rdata"
[1] "results_ca_specification_1nolag.Rdata"
[1] "results_ca_specification_2lag.Rdata"
[1] "results_ca_specification_2nolag.Rdata"
[1] "results_ca_specification_3lag.Rdata"
[1] "results_ca_specification_3nolag.Rdata"
[1] "results_ct_specification_0lag.Rdata"
[1] "results_ct_specification_0nolag.Rdata"
[1] "results_ct_specification_1lag.Rdata"
[1] "results_ct_specification_1nolag.Rdata"
[1] "results_ct_specification_2lag.Rdata"
[1] "results_ct_specification_2nolag.Rdata"
[1] "results_ct_specification_3lag.Rdata"
[1] "results_ct_specification_3nolag.Rdata"
[1] "results_fl_specification_0lag.Rdata"
[1] "results_fl_specification_0nolag.Rdata"
[1] "results_fl_specification_1lag.Rdata"
[1] "results_fl_specification_1nolag.Rdata"
[1] "results_fl_specification_2lag.Rdata"
[1] "results_fl_specification_2nolag.Rdata"
[1] "results_fl_specification_3lag.Rdata"
[1] "results_fl_specification_3nolag.Rdata"
[1] "results_il_specification_0lag.Rdata"
[1] "results_il_specification_0nolag.Rdata"
[1] "results_il_specification_1lag.Rdata"
[1] "results_il_specification_1nolag.Rdata"
[1] "results_il_specification_2lag.Rdata"
[1] "results_il_specification_2nolag.Rdata"
[1] "results_il_specification_3lag.Rdata"
[1] "results_il_specification_3nolag.Rdata"
[1] "results_in_specification_0lag.Rdata"
[1] "results_in_specification_0nolag.Rdata"
[1] "results_in_specification_1lag.Rdata"
[1] "results_in_specification_1nolag.Rdata"
[1] "results_in_specification_2lag.Rdata"
[1] "results_in_specification_2nolag.Rdata"
[1] "results_in_specification_3lag.Rdata"
[1] "results_in_specification_3nolag.Rdata"
[1] "results_ks_specification_0lag.Rdata"
[1] "results_ks_specification_0nolag.Rdata"
[1] "results_ks_specification_1lag.Rdata"
[1] "results_ks_specification_1nolag.Rdata"
[1] "results_ks_specification_2lag.Rdata"
[1] "results_ks_specification_2nolag.Rdata"
[1] "results_ks_specification_3lag.Rdata"
[1] "results_ks_specification_3nolag.Rdata"
[1] "results_ky_specification_0lag.Rdata"
[1] "results_ky_specification_0nolag.Rdata"
[1] "results_ky_specification_1lag.Rdata"
[1] "results_ky_specification_1nolag.Rdata"
[1] "results_ky_specification_2lag.Rdata"
[1] "results_ky_specification_2nolag.Rdata"
[1] "results_ky_specification_3lag.Rdata"
[1] "results_ky_specification_3nolag.Rdata"
[1] "results_ma_specification_0lag.Rdata"
[1] "results_ma_specification_0nolag.Rdata"
[1] "results_ma_specification_1lag.Rdata"
[1] "results_ma_specification_1nolag.Rdata"
[1] "results_ma_specification_2lag.Rdata"
[1] "results_ma_specification_2nolag.Rdata"
[1] "results_ma_specification_3lag.Rdata"
[1] "results_ma_specification_3nolag.Rdata"
[1] "results_md_specification_0lag.Rdata"
[1] "results_md_specification_0nolag.Rdata"
[1] "results_md_specification_1lag.Rdata"
[1] "results_md_specification_1nolag.Rdata"
[1] "results_md_specification_2lag.Rdata"
[1] "results_md_specification_2nolag.Rdata"
[1] "results_md_specification_3lag.Rdata"
[1] "results_md_specification_3nolag.Rdata"
[1] "results_mo_specification_0lag.Rdata"
[1] "results_mo_specification_0nolag.Rdata"
[1] "results_mo_specification_1lag.Rdata"
[1] "results_mo_specification_1nolag.Rdata"
[1] "results_mo_specification_2lag.Rdata"
[1] "results_mo_specification_2nolag.Rdata"
[1] "results_mo_specification_3lag.Rdata"
[1] "results_mo_specification_3nolag.Rdata"
[1] "results_ne_specification_0lag.Rdata"
[1] "results_ne_specification_0nolag.Rdata"
[1] "results_ne_specification_1lag.Rdata"
[1] "results_ne_specification_1nolag.Rdata"
[1] "results_ne_specification_2lag.Rdata"
[1] "results_ne_specification_2nolag.Rdata"
[1] "results_ne_specification_3lag.Rdata"
[1] "results_ne_specification_3nolag.Rdata"
[1] "results_nv_specification_0lag.Rdata"
[1] "results_nv_specification_0nolag.Rdata"
[1] "results_nv_specification_1lag.Rdata"
[1] "results_nv_specification_1nolag.Rdata"
[1] "results_nv_specification_2lag.Rdata"
[1] "results_nv_specification_2nolag.Rdata"
[1] "results_nv_specification_3lag.Rdata"
[1] "results_nv_specification_3nolag.Rdata"
[1] "results_ny_specification_0lag.Rdata"
[1] "results_ny_specification_0nolag.Rdata"
[1] "results_ny_specification_1lag.Rdata"
[1] "results_ny_specification_1nolag.Rdata"
[1] "results_ny_specification_2lag.Rdata"
[1] "results_ny_specification_2nolag.Rdata"
[1] "results_ny_specification_3lag.Rdata"
[1] "results_ny_specification_3nolag.Rdata"
[1] "results_oh_specification_0lag.Rdata"
[1] "results_oh_specification_0nolag.Rdata"
[1] "results_oh_specification_1lag.Rdata"
[1] "results_oh_specification_1nolag.Rdata"
[1] "results_oh_specification_2lag.Rdata"
[1] "results_oh_specification_2nolag.Rdata"
[1] "results_oh_specification_3lag.Rdata"
[1] "results_oh_specification_3nolag.Rdata"
[1] "results_or_specification_0lag.Rdata"
[1] "results_or_specification_0nolag.Rdata"
[1] "results_or_specification_1lag.Rdata"
[1] "results_or_specification_1nolag.Rdata"
[1] "results_or_specification_2lag.Rdata"
[1] "results_or_specification_2nolag.Rdata"
[1] "results_or_specification_3lag.Rdata"
[1] "results_or_specification_3nolag.Rdata"
[1] "results_pa_specification_0lag.Rdata"
[1] "results_pa_specification_0nolag.Rdata"
[1] "results_pa_specification_1lag.Rdata"
[1] "results_pa_specification_1nolag.Rdata"
[1] "results_pa_specification_2lag.Rdata"
[1] "results_pa_specification_2nolag.Rdata"
[1] "results_pa_specification_3lag.Rdata"
[1] "results_pa_specification_3nolag.Rdata"
[1] "results_ri_specification_0lag.Rdata"
[1] "results_ri_specification_0nolag.Rdata"
[1] "results_ri_specification_1lag.Rdata"
[1] "results_ri_specification_1nolag.Rdata"
[1] "results_ri_specification_2lag.Rdata"
[1] "results_ri_specification_2nolag.Rdata"
[1] "results_ri_specification_3lag.Rdata"
[1] "results_ri_specification_3nolag.Rdata"
[1] "results_sc_specification_0lag.Rdata"
[1] "results_sc_specification_0nolag.Rdata"
[1] "results_sc_specification_1lag.Rdata"
[1] "results_sc_specification_1nolag.Rdata"
[1] "results_sc_specification_2lag.Rdata"
[1] "results_sc_specification_2nolag.Rdata"
[1] "results_sc_specification_3lag.Rdata"
[1] "results_sc_specification_3nolag.Rdata"
[1] "results_tn_specification_0lag.Rdata"
[1] "results_tn_specification_0nolag.Rdata"
[1] "results_tn_specification_1lag.Rdata"
[1] "results_tn_specification_1nolag.Rdata"
[1] "results_tn_specification_2lag.Rdata"
[1] "results_tn_specification_2nolag.Rdata"
[1] "results_tn_specification_3lag.Rdata"
[1] "results_tn_specification_3nolag.Rdata"
[1] "results_tx_specification_0lag.Rdata"
[1] "results_tx_specification_0nolag.Rdata"
[1] "results_tx_specification_1lag.Rdata"
[1] "results_tx_specification_1nolag.Rdata"
[1] "results_tx_specification_2lag.Rdata"
[1] "results_tx_specification_2nolag.Rdata"
[1] "results_tx_specification_3lag.Rdata"
[1] "results_tx_specification_3nolag.Rdata"
[1] "results_va_specification_0lag.Rdata"
[1] "results_va_specification_0nolag.Rdata"
[1] "results_va_specification_1lag.Rdata"
[1] "results_va_specification_1nolag.Rdata"
[1] "results_va_specification_2lag.Rdata"
[1] "results_va_specification_2nolag.Rdata"
[1] "results_va_specification_3lag.Rdata"
[1] "results_va_specification_3nolag.Rdata"
[1] "results_wa_specification_0lag.Rdata"
[1] "results_wa_specification_0nolag.Rdata"
[1] "results_wa_specification_1lag.Rdata"
[1] "results_wa_specification_1nolag.Rdata"
[1] "results_wa_specification_2lag.Rdata"
[1] "results_wa_specification_2nolag.Rdata"
[1] "results_wa_specification_3lag.Rdata"
[1] "results_wa_specification_3nolag.Rdata"
[1] "results_wv_specification_0lag.Rdata"
[1] "results_wv_specification_0nolag.Rdata"
[1] "results_wv_specification_1lag.Rdata"
[1] "results_wv_specification_1nolag.Rdata"
[1] "results_wv_specification_2lag.Rdata"
[1] "results_wv_specification_2nolag.Rdata"
[1] "results_wv_specification_3lag.Rdata"
[1] "results_wv_specification_3nolag.Rdata"

> data = results_df

> output = list()

> for(sp in unique(data$specification)){
+   holder = list()
+   for(l in unique(data$lag)){
+     
+     block = data[data$lag ==l & data$specification == sp,]
+     predictions_white = as.data.frame(matrix(NA, ncol = 7))
+     predictions_black = as.data.frame(matrix(NA, ncol = 7))
+     predictions_hispanic = as.data.frame(matrix(NA, ncol = 7))
+     
+     
+ 
+     for(j in 1:length(unique(block$dv))){
+       if(length(block$dv[block$dv == unique(block$dv)[j]]) > 0){
+         
+         preds_white = meta.maker(block$coef[block$race == "white"  & block$dv == unique(block$dv)[j] ], block$se[ block$race == "white" & block$dv == unique(block$dv)[j]])
+         predictions_white = rbind(predictions_white, c(sp,l, unique(block$dv)[j], preds_white$est, preds_white$se, "white", "2008"))
+         
+         preds_black = meta.maker(block$coef[ block$race == "black" & block$dv == unique(block$dv)[j]], block$se[ block$race == "black"  & block$dv == unique(block$dv)[j]])
+         predictions_black = rbind(predictions_black, c(sp,l, unique(block$dv)[j], preds_black$est, preds_black$se, "black", "2008"))
+         
+         preds_hispanic = meta.maker(block$coef[ block$race == "hispanic" &  block$dv == unique(block$dv)[j]], block$se[ block$race == "hispanic" & block$dv == unique(block$dv)[j]])
+         predictions_hispanic = rbind(predictions_hispanic, c(sp,l, unique(block$dv)[j], preds_hispanic$est, preds_hispanic$se, "hispanic", "2008"))
+         
+         
+         
+         
+         
+       }
+       
+     }
+     
+     meta_plot=rbind(predictions_white, predictions_black, predictions_hispanic )
+     colnames(meta_plot)=c('specification', 'lag', 'dv', 'coef', 'se', 'race', 'ev' )
+     holder[[l]]=meta_plot
+     rm(meta_plot,predictions_white,predictions_black,predictions_hispanic, block)
+   }
+   output[[paste0("spec",sp)]]=holder
+ }

> df = rbind(output$spec0$lag, 
+            output$spec0$nolag,
+            output$spec2$lag, 
+            output$spec2$nolag,
+            output$spec3$lag, 
+            output$spec3$nolag,
+            output$spec1$nolag)

> df = df[!is.na(df$specification),]

> df$coef = as.numeric(df$coef)

> df$se = as.numeric(df$se)

> out = data.frame(file = c('alt_results_lag_spec0.pdf', 'alt_results_lag_spec2.pdf', 'alt_results_lag_spec3.pdf',
+                           'alt_results_nolag_spec1.pdf', 'alt_results_nolag_spec0.pdf', 'alt_results_nolag_spec2.pdf', 'alt_results_nolag_spec3.pdf'),
+                  out.path = paste0('figures/FigS',13:19,'.pdf'))

> for(sp in unique(df$specification)){
+   for(l in unique(df$lag)){
+     if(!(l=='lag' & sp =='1')){
+     plt = df[  df$lag == l & df$specification == sp,]
+     p=ggplot(data = plt[plt$dv %in% c("Vote 2010","Vote 2012", "Vote 2014", "Vote 2016"),]%>%
+                mutate(race=Hmisc::capitalize(race))%>%
+                mutate(race=factor(race,levels = c('Black','White','Hispanic'))), aes(x = dv, y = coef, color = race, fill = race)) +
+       geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+       geom_point(shape = 21, size = 6, position=position_dodge(.5)) + xlab('') +
+       ylab('Effect of 2008 Voting on Future Voting') + 
+       geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se),linetype = "solid", width=0,
+                     position=position_dodge(.5)) +
+       scale_color_manual(values = c("black", "black", "black"))+
+       scale_fill_manual(values = c("black", "white", "grey"))+
+       guides(linetype=F)+
+       theme_minimal()+
+       scale_x_discrete(labels = c('2010', '2012',"2014", "2016"))+
+       theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+             axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+             legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+       NULL
+     f= paste0("alt_results_",l,"_spec",sp,".pdf")
+     ggsave(plot = p,filename = out$out.path[out$file==f], dpi = 300, width = 9, height = 6, units = 'in')
+     
+   }
+ }
+ }

> # Figures S20-S23
> 
> rm(list=ls())

> gc()
          used  (Mb) gc trigger  (Mb) limit (Mb)  max used   (Mb)
Ncells 3996675 213.5    6242985 333.5         NA   6242985  333.5
Vcells 7745236  59.1   97359217 742.8      16384 382317008 2916.9

> source('primary_analysis_gender_state_loop.R', echo = T, max.deparse.length=10000)

> rm(list=ls())

> gc()
          used  (Mb) gc trigger  (Mb) limit (Mb)  max used   (Mb)
Ncells 3996483 213.5    6242985 333.5         NA   6242985  333.5
Vcells 7729794  59.0   77887374 594.3      16384 382317008 2916.9

> require(rddtools)

> require(AER)

> require(tidyverse)

> require(rdrobust)

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> for(state in states){
+   file = paste0('rdd_',state,'.Rdata')
+   load(file)
+   source('primary_analysis_rdd_gender.R')
+   print(state)
+   
+   
+ }
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"

> source('FigS20_FigS21_FigS22_FigS23.R', echo = T, max.deparse.length=10000)

> rm(list=ls())

> require(tidyverse)

> require(plyr)

> require(dplyr)

> require(scales)

> require(rmeta)

> files = list.files('results')[grepl("_gender",list.files('results'))]

> results = as.data.frame(matrix(nrow = 0, ncol = 8))

> colnames(results) = c("coef", "se", "race", "dv", "p value", "endog", "state", 'gender')

> for(f in files){
+   load(paste0("results/", f))
+   holder = as.data.frame(matrix(nrow = 42, ncol = 8))
+   colnames(holder) = c("coef", "se", "race", "dv", "p value", "endog", "state", 'gender')
+   
+   holder$coef = c(ivmod1_white_male$cace,  ivmod1_black_male$cace, ivmod1_hispanic_male$cace,
+                    ivmod2_white_male$cace,  ivmod2_black_male$cace, ivmod2_hispanic_male$cace,
+                    ivmod3_white_male$cace,  ivmod3_black_male$cace, ivmod3_hispanic_male$cace,
+                    ivmod4_white_male$cace,  ivmod4_black_male$cace, ivmod4_hispanic_male$cace,
+                    ivmod5_white_male$cace,  ivmod5_black_male$cace, ivmod5_hispanic_male$cace,
+                    ivmod6_white_male$cace,  ivmod6_black_male$cace, ivmod6_hispanic_male$cace,
+                    ivmod_rep_white_male$cace,  ivmod_rep_black_male$cace, ivmod_rep_hispanic_male$cace,
+                   
+                    
+                    
+                   
+                   
+                   ivmod1_white_female$cace,  ivmod1_black_female$cace, ivmod1_hispanic_female$cace,
+                   ivmod2_white_female$cace,  ivmod2_black_female$cace, ivmod2_hispanic_female$cace,
+                   ivmod3_white_female$cace,  ivmod3_black_female$cace, ivmod3_hispanic_female$cace,
+                   ivmod4_white_female$cace,  ivmod4_black_female$cace, ivmod4_hispanic_female$cace,
+                   ivmod5_white_female$cace,  ivmod5_black_female$cace, ivmod5_hispanic_female$cace,
+                   ivmod6_white_female$cace,  ivmod6_black_female$cace, ivmod6_hispanic_female$cace,
+                   ivmod_rep_white_female$cace,  ivmod_rep_black_female$cace, ivmod_rep_hispanic_female$cace
+                   
+                   
+                   
+                   
+                    
+                    
+                    
+                    
+                    
+                    )
+   
+   holder$se = c(ivmod1_white_male$se,  ivmod1_black_male$se, ivmod1_hispanic_male$se,
+                 ivmod2_white_male$se,  ivmod2_black_male$se, ivmod2_hispanic_male$se,
+                 ivmod3_white_male$se,  ivmod3_black_male$se, ivmod3_hispanic_male$se,
+                 ivmod4_white_male$se,  ivmod4_black_male$se, ivmod4_hispanic_male$se,
+                 ivmod5_white_male$se,  ivmod5_black_male$se, ivmod5_hispanic_male$se,
+                 ivmod6_white_male$se,  ivmod6_black_male$se, ivmod6_hispanic_male$se,
+                 ivmod_rep_white_male$se,  ivmod_rep_black_male$se, ivmod_rep_hispanic_male$se,
+                 
+                 
+                 
+                
+                 ivmod1_white_female$se,  ivmod1_black_female$se, ivmod1_hispanic_female$se,
+                 ivmod2_white_female$se,  ivmod2_black_female$se, ivmod2_hispanic_female$se,
+                 ivmod3_white_female$se,  ivmod3_black_female$se, ivmod3_hispanic_female$se,
+                 ivmod4_white_female$se,  ivmod4_black_female$se, ivmod4_hispanic_female$se,
+                 ivmod5_white_female$se,  ivmod5_black_female$se, ivmod5_hispanic_female$se,
+                 ivmod6_white_female$se,  ivmod6_black_female$se, ivmod6_hispanic_female$se,
+                 ivmod_rep_white_female$se,  ivmod_rep_black_female$se, ivmod_rep_hispanic_female$se
+                 
+                 
+                 
+                 
+                  
+                  
+                  
+   )
+   
+   holder$`p value` = c(ivmod1_white_male$summary$coefficients[2,4],  ivmod1_black_male$summary$coefficients[2,4], ivmod1_hispanic_male$summary$coefficients[2,4],
+                        ivmod2_white_male$summary$coefficients[2,4],  ivmod2_black_male$summary$coefficients[2,4], ivmod2_hispanic_male$summary$coefficients[2,4],
+                        ivmod3_white_male$summary$coefficients[2,4],  ivmod3_black_male$summary$coefficients[2,4], ivmod3_hispanic_male$summary$coefficients[2,4],
+                        ivmod4_white_male$summary$coefficients[2,4],  ivmod4_black_male$summary$coefficients[2,4], ivmod4_hispanic_male$summary$coefficients[2,4],
+                        ivmod5_white_male$summary$coefficients[2,4],  ivmod5_black_male$summary$coefficients[2,4], ivmod5_hispanic_male$summary$coefficients[2,4],
+                        ivmod6_white_male$summary$coefficients[2,4],  ivmod6_black_male$summary$coefficients[2,4], ivmod6_hispanic_male$summary$coefficients[2,4],
+                        ivmod_rep_white_male$summary$coefficients[2,4],  ivmod_rep_black_male$summary$coefficients[2,4], ivmod_rep_hispanic_male$summary$coefficients[2,4],
+                        
+                        
+                        
+                        ivmod1_white_female$summary$coefficients[2,4],  ivmod1_black_female$summary$coefficients[2,4], ivmod1_hispanic_female$summary$coefficients[2,4],
+                        ivmod2_white_female$summary$coefficients[2,4],  ivmod2_black_female$summary$coefficients[2,4], ivmod2_hispanic_female$summary$coefficients[2,4],
+                        ivmod3_white_female$summary$coefficients[2,4],  ivmod3_black_female$summary$coefficients[2,4], ivmod3_hispanic_female$summary$coefficients[2,4],
+                        ivmod4_white_female$summary$coefficients[2,4],  ivmod4_black_female$summary$coefficients[2,4], ivmod4_hispanic_female$summary$coefficients[2,4],
+                        ivmod5_white_female$summary$coefficients[2,4],  ivmod5_black_female$summary$coefficients[2,4], ivmod5_hispanic_female$summary$coefficients[2,4],
+                        ivmod6_white_female$summary$coefficients[2,4],  ivmod6_black_female$summary$coefficients[2,4], ivmod6_hispanic_female$summary$coefficients[2,4],
+                        ivmod_rep_white_female$summary$coefficients[2,4],  ivmod_rep_black_female$summary$coefficients[2,4], ivmod_rep_hispanic_female$summary$coefficients[2,4]
+                    
+                        
+                         
+                         
+   )
+   
+   ##############
+   holder$race = c(rep(c("white","black", "hispanic"), 14))
+   holder$gender = c(rep('male', 21), rep('female', 21))
+   
+   holder$dv = c(c(rep("Vote 2016", 3),
+                  rep("Vote 2014", 3),
+                  rep("Vote 2012", 3),
+                  rep("Vote 2010", 3),
+                  rep("Democrat", 3),
+                  rep("Registered", 3),
+                  rep("Republican", 3)),
+                  
+                 
+                 
+                 c(rep("Vote 2016", 3),
+                   rep("Vote 2014", 3),
+                   rep("Vote 2012", 3),
+                   rep("Vote 2010", 3),
+                   rep("Democrat", 3),
+                   rep("Registered", 3),
+                   rep("Republican", 3))
+                  
+                  )
+   
+   
+   holder$endog = c(rep("Vote 2008", 7*3),
+                    rep("Vote 2008", 7*3))
+   holder$state = sub("results_","", sub("_gender.Rdata", "", f))
+ 
+   
+   results = rbind(results, holder)
+   
+   print(f); print(nrow(results))
+ }
[1] "results_al_gender.Rdata"
[1] 42
[1] "results_ar_gender.Rdata"
[1] 84
[1] "results_ca_gender.Rdata"
[1] 126
[1] "results_ct_gender.Rdata"
[1] 168
[1] "results_fl_gender.Rdata"
[1] 210
[1] "results_il_gender.Rdata"
[1] 252
[1] "results_in_gender.Rdata"
[1] 294
[1] "results_ks_gender.Rdata"
[1] 336
[1] "results_ky_gender.Rdata"
[1] 378
[1] "results_ma_gender.Rdata"
[1] 420
[1] "results_md_gender.Rdata"
[1] 462
[1] "results_mo_gender.Rdata"
[1] 504
[1] "results_ne_gender.Rdata"
[1] 546
[1] "results_nv_gender.Rdata"
[1] 588
[1] "results_ny_gender.Rdata"
[1] 630
[1] "results_oh_gender.Rdata"
[1] 672
[1] "results_or_gender.Rdata"
[1] 714
[1] "results_pa_gender.Rdata"
[1] 756
[1] "results_ri_gender.Rdata"
[1] 798
[1] "results_sc_gender.Rdata"
[1] 840
[1] "results_tn_gender.Rdata"
[1] 882
[1] "results_tx_gender.Rdata"
[1] 924
[1] "results_va_gender.Rdata"
[1] 966
[1] "results_wa_gender.Rdata"
[1] 1008
[1] "results_wv_gender.Rdata"
[1] 1050

> rm(list=ls()[grepl('mod',ls())])

> ggsave(filename = 'figures/FigS21.pdf', width = 9, height = 5, 
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race), gender = Hmisc::capitalize(gender))%>%
+   filter(endog=='Vote 2008', grepl('Vote', dv))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, fill = race,linetype=race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dotted', 'dashed', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.1,.5)+
+   theme(legend.title=element_blank(), legend.position = 'bottom', legend.spacing.x = unit(.25, 'cm'),
+         axis.title.y=element_blank(), axis.text.y=element_blank(),
+         axis.ticks.y=element_blank())+  facet_wrap(dv ~ gender, nrow = 4)
+ )

> pid.states = read_csv('state_fips.csv')%>%
+   filter(record_pid==1)%>%
+   pull(state_abbr)%>%
+   tolower()
[1mindexing[0m [34mstate_fips.csv[0m [=======================================================================================] [32m800.37MB/s[0m, eta: [36m 0s[0m                                                                                                                                                                         Rows: 51 Columns: 11
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): state_name, state_abbr, long_name, region_name, division_name
dbl (6): fips, sumlev, region, division, state, record_pid

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

> ggsave(filename = 'figures/FigS23.pdf', width = 9, height = 5,
+ plot = results %>%
+   mutate(race=Hmisc::capitalize(race), gender = Hmisc::capitalize(gender),
+          dv=factor(dv, levels = c("Vote 2016",   "Vote 2014"  , "Vote 2012" ,  "Vote 2010" , "Registered" , "Democrat" ,   
+                                   "Republican", "Major Party")))%>%
+   filter(endog=='Vote 2008', dv%in%c('Registered', 'Democrat', 'Republican'))%>%
+   mutate(race = factor(race, levels = c('Hispanic','White',  'Black')),
+          coef = ifelse(dv %in% c('Democrat', 'Republican') & !state %in% pid.states, NA, coef),
+          se = ifelse(dv %in% c('Democrat', 'Republican') & !state %in% pid.states, NA, se))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, fill = race,linetype=race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   guides(fill = guide_legend(reverse = TRUE), linetype = guide_legend(reverse = TRUE))+
+   scale_linetype_manual(values = c('dotted', 'dashed', 'solid'))+
+   scale_fill_manual(values = c('grey','white',  'black'))+
+   xlim(-0.3,1)+
+   ylab('Density')+
+   theme(legend.title=element_blank(), legend.position = 'bottom', legend.spacing.x = unit(.25, 'cm'),
+         axis.title.y=element_blank(), axis.text.y=element_blank(),
+         axis.ticks.y=element_blank())+  facet_wrap(dv ~ gender, nrow =3)
+ )

> ## Weighted averages
> 
> data = results %>%
+   filter(!dv %in% c('Democrat','Republican'))

> predictions_female_white = as.data.frame(matrix(NA, ncol = 6))

> predictions_female_black = as.data.frame(matrix(NA, ncol = 6))

> predictions_female_hispanic = as.data.frame(matrix(NA, ncol = 6))

> predictions_male_white = as.data.frame(matrix(NA, ncol = 6))

> predictions_male_black = as.data.frame(matrix(NA, ncol = 6))

> predictions_male_hispanic = as.data.frame(matrix(NA, ncol = 6))

> colnames(predictions_female_white) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_female_black) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_female_hispanic) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_male_white) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_male_black) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_male_hispanic) = c("ev", "dv", "coef", "se", "race", "gender")

> predictions_female_white$race = "white"

> predictions_female_black$race = "black"

> predictions_female_hispanic$race = "hispanic"

> predictions_male_white$race = "white"

> predictions_male_black$race = "black"

> predictions_male_hispanic$race = "hispanic"

> predictions_female_white$gender = "female"

> predictions_female_black$gender = "female"

> predictions_female_hispanic$gender = "female"

> predictions_male_white$gender = "male"

> predictions_male_black$gender = "male"

> predictions_male_hispanic$gender = "male"

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_female_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "female" & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "female"& data$dv == unique(data$dv)[j]])
+       predictions_female_white = rbind(predictions_female_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_female_white$est, preds_female_white$se, "white", "female"))
+       
+       preds_female_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "female"& data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "female"& data$dv == unique(data$dv)[j]])
+       predictions_female_black = rbind(predictions_female_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_female_black$est, preds_female_black$se, "black", "female"))
+       
+       preds_female_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "female" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "female"& data$dv == unique(data$dv)[j]])
+       predictions_female_hispanic = rbind(predictions_female_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_female_hispanic$est, preds_female_hispanic$se, "hispanic", "female"))
+       
+       preds_male_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "male" & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "male"& data$dv == unique(data$dv)[j]])
+       predictions_male_white = rbind(predictions_male_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_male_white$est, preds_male_white$se, "white", "male"))
+       
+       preds_male_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "male"& data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "male"& data$dv == unique(data$dv)[j]])
+       predictions_male_black = rbind(predictions_male_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_male_black$est, preds_male_black$se, "black", "male"))
+       
+       preds_male_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "male" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "male"& data$dv == unique(data$dv)[j]])
+       predictions_male_hispanic = rbind(predictions_male_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_male_hispanic$est, preds_male_hispanic$se, "hispanic", "male"))
+       
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_female_white, predictions_female_black, predictions_female_hispanic,
+                 predictions_male_white, predictions_male_black, predictions_male_hispanic)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> holder = meta_plot

> data = results %>%
+   filter(dv %in% c('Democrat','Republican') & state %in% pid.states)

> predictions_female_white = as.data.frame(matrix(NA, ncol = 6))

> predictions_female_black = as.data.frame(matrix(NA, ncol = 6))

> predictions_female_hispanic = as.data.frame(matrix(NA, ncol = 6))

> predictions_male_white = as.data.frame(matrix(NA, ncol = 6))

> predictions_male_black = as.data.frame(matrix(NA, ncol = 6))

> predictions_male_hispanic = as.data.frame(matrix(NA, ncol = 6))

> colnames(predictions_female_white) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_female_black) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_female_hispanic) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_male_white) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_male_black) = c("ev", "dv", "coef", "se", "race", "gender")

> colnames(predictions_male_hispanic) = c("ev", "dv", "coef", "se", "race", "gender")

> predictions_female_white$race = "white"

> predictions_female_black$race = "black"

> predictions_female_hispanic$race = "hispanic"

> predictions_male_white$race = "white"

> predictions_male_black$race = "black"

> predictions_male_hispanic$race = "hispanic"

> predictions_female_white$gender = "female"

> predictions_female_black$gender = "female"

> predictions_female_hispanic$gender = "female"

> predictions_male_white$gender = "male"

> predictions_male_black$gender = "male"

> predictions_male_hispanic$gender = "male"

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_female_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "female" & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "female"& data$dv == unique(data$dv)[j]])
+       predictions_female_white = rbind(predictions_female_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_female_white$est, preds_female_white$se, "white", "female"))
+       
+       preds_female_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "female"& data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "female"& data$dv == unique(data$dv)[j]])
+       predictions_female_black = rbind(predictions_female_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_female_black$est, preds_female_black$se, "black", "female"))
+       
+       preds_female_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "female" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "female"& data$dv == unique(data$dv)[j]])
+       predictions_female_hispanic = rbind(predictions_female_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_female_hispanic$est, preds_female_hispanic$se, "hispanic", "female"))
+       
+       preds_male_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "male" & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$gender == "male"& data$dv == unique(data$dv)[j]])
+       predictions_male_white = rbind(predictions_male_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_male_white$est, preds_male_white$se, "white", "male"))
+       
+       preds_male_black = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "male"& data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "black" & data$gender == "male"& data$dv == unique(data$dv)[j]])
+       predictions_male_black = rbind(predictions_male_black, c(unique(data$endog)[i], unique(data$dv)[j], preds_male_black$est, preds_male_black$se, "black", "male"))
+       
+       preds_male_hispanic = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "male" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "hispanic" & data$gender == "male"& data$dv == unique(data$dv)[j]])
+       predictions_male_hispanic = rbind(predictions_male_hispanic, c(unique(data$endog)[i], unique(data$dv)[j], preds_male_hispanic$est, preds_male_hispanic$se, "hispanic", "male"))
+       
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_female_white, predictions_female_black, predictions_female_hispanic,
+                 predictions_male_white, predictions_male_black, predictions_male_hispanic)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> meta_plot = rbind(holder,meta_plot)

> plt = meta_plot%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Black', 'White', 'Hispanic')),
+          gender =Hmisc::capitalize(gender),
+          dv = factor(dv, levels = c("Vote 2010", "Vote 2012", "Vote 2014", "Vote 2016", 'Registered', 'Democrat', 'Republican')))

> ggsave(filename = "figures/FigS20.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c("Vote 2010", "Vote 2012", "Vote 2014", "Vote 2016"),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape=21,size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   guides(shape=F)+
+   scale_x_discrete(labels = c("2010", "2012", "2014", "2016"))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   facet_grid(.~gender)+
+   NULL
+ )

> ggsave(filename = "figures/FigS22.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c("Registered", 'Democrat', 'Republican'),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape=21,size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Registration') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("Registered", "Democrat", 'Republican'))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   facet_grid(.~gender)+
+   NULL
+ )

> # Figures S24 and S25 created in prior script
> 
> 
> # Figures S26-S29
> 
> rm(list=ls())

> gc()
          used  (Mb) gc trigger   (Mb) limit (Mb)  max used   (Mb)
Ncells 3997242 213.5    6242985  333.5         NA   6242985  333.5
Vcells 7729385  59.0  158976800 1212.9      16384 382317008 2916.9

> source('primary_analysis_state_loop_nonwhite.R', echo = T, max.deparse.length=10000)

> rm(list=ls())

> require(rddtools)

> require(AER)

> require(tidyverse)

> require(rdrobust)

> source('Habit_source.R', echo=TRUE)

> # Coppock and Green (2015): Is Voting Habit Forming? New Evidence from Experiments and Regression Discontinuities
> # Helper functions
> 
> 
> bias_ .... [TRUNCATED] 

> complier.control.mean <- function(Y,D,Z){
+   pr.c <- mean(D[Z==1]) - mean(D[Z==0])
+   pr.at <- mean(D[Z==0])
+   pr.nt <- 1 - pr.c - pr.at
+   Y0. .... [TRUNCATED] 

> cl   <- function(dat,fm, cluster){
+   require(sandwich, quietly = TRUE)
+   require(lmtest, quietly = TRUE)
+   M <- length(unique(cluster))
+   N  .... [TRUNCATED] 

> state.cace.estimator <-function(data, upstream, downstream, bandwidth, state.abbrev=NULL){
+   require(AER)
+   require(lmtest)
+   if(!is.null(stat .... [TRUNCATED] 

> state.cace.estimator.order <-function(data, upstream_treat,upstream_days, upstream_voted, downstream_voted, downstream_lag, order=1, lag="no",bandwi .... [TRUNCATED] 

> state.cace.estimator.primary <-function(data, upstream_days, upstream_treat, upstream_voted, 
+                                         downstream_v .... [TRUNCATED] 

> meta.maker <- function(x, y){
+   x <- x[!is.na(x)]
+   y <- y[!is.na(y)]
+   meta.results <- meta.summaries(x,y)
+   return(list(est=meta.results$s .... [TRUNCATED] 

> commarobust <- function(fit){
+   require(lmtest)
+   require(sandwich)
+   coeftest(fit,vcovHC(fit))
+ }

> getrobustses <- function(fit){
+   robustfit <- commarobust(fit)
+   return(robustfit[,2])
+ }

> makerobustseslist <- function(fitlist){
+   return(lapply(fitlist, FUN=getrobustses) )
+ }

> states = tolower(c("AL", "AR", "CA", "CT", "FL", "IL", "IN", "KS", "KY", "MA", "MD",
+                    "MO",
+                    "NE", "NV", "NY", "OH", "OR", "PA", "RI", "SC", "TN", "TX", "VA", "WA",
+                    "WV"))

> for(state in states){
+   file = paste0('rdd_',state,'.Rdata')
+   load(file)
+   source('primary_analysis_rdd_nonwhite.R')
+   print(state)
+   
+   
+ }
[1] "al"
[1] "ar"
[1] "ca"
[1] "ct"
[1] "fl"
[1] "il"
[1] "in"
[1] "ks"
[1] "ky"
[1] "ma"
[1] "md"
[1] "mo"
[1] "ne"
[1] "nv"
[1] "ny"
[1] "oh"
[1] "or"
[1] "pa"
[1] "ri"
[1] "sc"
[1] "tn"
[1] "tx"
[1] "va"
[1] "wa"
[1] "wv"

> source('FigS26_FigS27_FigS28_FigS29.R', echo = T, max.deparse.length=10000)

> rm(list=ls())

> require(tidyverse)

> require(plyr)

> require(dplyr)

> require(scales)

> require(rmeta)

> files = list.files('results')[grepl("_nonwhite",list.files('results'))]

> results = as.data.frame(matrix(nrow = 0, ncol = 7))

> colnames(results) = c("coef", "se", "race", "dv", "p value", "endog", "state")

> for(f in files){
+   load(paste0("results/", f))
+   holder = as.data.frame(matrix(nrow = 14, ncol = 7))
+   colnames(holder) = c("coef", "se", "race", "dv", "p value", "endog", "state")
+   
+   holder$coef = c(ivmod1_white$cace, ivmod1_nonwhite$cace,
+                    ivmod2_white$cace, ivmod2_nonwhite$cace,
+                    ivmod3_white$cace, ivmod3_nonwhite$cace,
+                    ivmod4_white$cace, ivmod4_nonwhite$cace,
+                    ivmod5_white$cace, ivmod5_nonwhite$cace,
+                    ivmod6_white$cace, ivmod6_nonwhite$cace,
+                    ivmod_rep_white$cace, ivmod_rep_nonwhite$cace
+                    
+                    
+                    
+                    
+                    
+                    )
+   
+   holder$se = c(ivmod1_white$se, ivmod1_nonwhite$se, 
+                 ivmod2_white$se, ivmod2_nonwhite$se, 
+                 ivmod3_white$se, ivmod3_nonwhite$se,
+                 ivmod4_white$se, ivmod4_nonwhite$se, 
+                 ivmod5_white$se, ivmod5_nonwhite$se, 
+                 ivmod6_white$se, ivmod6_nonwhite$se, 
+                 ivmod_rep_white$se, ivmod_rep_nonwhite$se
+                 
+                 
+                 
+                  
+                  
+                  
+   )
+   
+   holder$`p value` = c(ivmod1_white$summary$coefficients[2,4], ivmod1_nonwhite$summary$coefficients[2,4],
+                        ivmod2_white$summary$coefficients[2,4], ivmod2_nonwhite$summary$coefficients[2,4],
+                        ivmod3_white$summary$coefficients[2,4], ivmod3_nonwhite$summary$coefficients[2,4], 
+                        ivmod4_white$summary$coefficients[2,4], ivmod4_nonwhite$summary$coefficients[2,4], 
+                        ivmod5_white$summary$coefficients[2,4], ivmod5_nonwhite$summary$coefficients[2,4], 
+                        ivmod6_white$summary$coefficients[2,4], ivmod6_nonwhite$summary$coefficients[2,4], 
+                        ivmod_rep_white$summary$coefficients[2,4], ivmod_rep_nonwhite$summary$coefficients[2,4]
+                        
+                        
+                        
+                         
+                         
+   )
+   ############itt
+  
+   ##############
+   holder$race = c(rep(c("white", "non-white"), 7))
+   
+   holder$dv = c(c(rep("Vote 2016", 2),
+                  rep("Vote 2014", 2),
+                  rep("Vote 2012", 2),
+                  rep("Vote 2010", 2),
+                  rep("Democrat", 2),
+                  rep("Registered", 2),
+                  rep("Republican", 2))
+                  
+                  )
+   
+   
+   holder$endog = c(rep("Vote 2008", 7*2))
+   holder$state = sub("results_","", sub("_nonwhite.Rdata", "", f))
+ 
+   
+   results = rbind(results, holder)
+   
+   print(f); print(nrow(results))
+ }
[1] "results_al_nonwhite.Rdata"
[1] 14
[1] "results_ar_nonwhite.Rdata"
[1] 28
[1] "results_ca_nonwhite.Rdata"
[1] 42
[1] "results_ct_nonwhite.Rdata"
[1] 56
[1] "results_fl_nonwhite.Rdata"
[1] 70
[1] "results_il_nonwhite.Rdata"
[1] 84
[1] "results_in_nonwhite.Rdata"
[1] 98
[1] "results_ks_nonwhite.Rdata"
[1] 112
[1] "results_ky_nonwhite.Rdata"
[1] 126
[1] "results_ma_nonwhite.Rdata"
[1] 140
[1] "results_md_nonwhite.Rdata"
[1] 154
[1] "results_mo_nonwhite.Rdata"
[1] 168
[1] "results_ne_nonwhite.Rdata"
[1] 182
[1] "results_nv_nonwhite.Rdata"
[1] 196
[1] "results_ny_nonwhite.Rdata"
[1] 210
[1] "results_oh_nonwhite.Rdata"
[1] 224
[1] "results_or_nonwhite.Rdata"
[1] 238
[1] "results_pa_nonwhite.Rdata"
[1] 252
[1] "results_ri_nonwhite.Rdata"
[1] 266
[1] "results_sc_nonwhite.Rdata"
[1] 280
[1] "results_tn_nonwhite.Rdata"
[1] 294
[1] "results_tx_nonwhite.Rdata"
[1] 308
[1] "results_va_nonwhite.Rdata"
[1] 322
[1] "results_wa_nonwhite.Rdata"
[1] 336
[1] "results_wv_nonwhite.Rdata"
[1] 350

> data = results %>%
+   mutate(race=ifelse(race=='white', 'White', 'Non-white'))

> pid.states = read_csv('state_fips.csv')%>%
+   filter(record_pid==1)%>%
+   pull(state_abbr)%>%
+   tolower()
[1mindexing[0m [34mstate_fips.csv[0m [=======================================================================================] [32m400.19MB/s[0m, eta: [36m 0s[0m                                                                                                                                                                         Rows: 51 Columns: 11
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): state_name, state_abbr, long_name, region_name, division_name
dbl (6): fips, sumlev, region, division, state, record_pid

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

> ggsave(filename = 'figures/FigS27.pdf', width = 9, height = 5, 
+ plot = data %>%
+   filter(endog=='Vote 2008', grepl('Vote', dv))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, fill = race,linetype=race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   scale_linetype_manual(values = c( 'solid', 'dashed'))+
+   scale_fill_manual(values = c('black','white'))+
+   xlim(-0.1,.5)+
+   ylab('Density')+
+   theme(legend.title=element_blank(), legend.position = 'bottom', legend.spacing.x = unit(.25, 'cm'),
+         axis.title.y=element_blank(), axis.text.y=element_blank(),
+         axis.ticks.y=element_blank())+  facet_wrap(dv ~ ., nrow = 4)
+ )

> ggsave(filename = 'figures/FigS29.pdf', width = 9, height = 5, 
+ plot = data %>%
+   filter(endog=='Vote 2008', !grepl('Vote', dv))%>%
+   mutate(dv = factor(dv, levels = c('Registered','Democrat', 'Republican')),
+          coef = ifelse(dv %in% c('Democrat', 'Republican') & !state %in% pid.states, NA, coef),
+          se = ifelse(dv %in% c('Democrat', 'Republican') & !state %in% pid.states, NA, se))%>%
+   ggplot(aes(x=coef, y = ..scaled..,weight = 1/(se^2), group = race, fill = race,linetype=race))+
+   geom_density(alpha=.5)+
+   xlab('State-Level Effects')+
+   theme_minimal()+
+   scale_linetype_manual(values = c( 'solid', 'dashed'))+
+   scale_fill_manual(values = c('black','white'))+
+   xlim(-0.1,.5)+
+   ylab('Density')+
+   theme(legend.title=element_blank(), legend.position = 'bottom', legend.spacing.x = unit(.25, 'cm'),
+         axis.title.y=element_blank(), axis.text.y=element_blank(),
+         axis.ticks.y=element_blank())+  facet_wrap(dv ~ ., nrow = 4)
+ )

> # Weighted average
> 
> # registration weighted average effect
> predictions_white = as.data.frame(matrix(NA, ncol = 5))

> predictions_nonwhite = as.data.frame(matrix(NA, ncol = 5))

> colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_nonwhite) = c("ev", "dv", "coef", "se", "race")

> data = results %>%
+   filter(!dv %in% c('Democrat','Republican'))

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white"  & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_nonwhite = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "non-white" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "non-white" & data$dv == unique(data$dv)[j]])
+       predictions_nonwhite = rbind(predictions_nonwhite, c(unique(data$endog)[i], unique(data$dv)[j], preds_nonwhite$est, preds_nonwhite$se, "non-white"))
+    
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_white, predictions_nonwhite)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> plt1 = meta_plot%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Non-white', 'White')))

> predictions_white = as.data.frame(matrix(NA, ncol = 5))

> predictions_nonwhite = as.data.frame(matrix(NA, ncol = 5))

> colnames(predictions_white) = c("ev", "dv", "coef", "se", "race")

> colnames(predictions_nonwhite) = c("ev", "dv", "coef", "se", "race")

> data = results %>%
+   filter(state %in% pid.states & dv %in% c('Democrat', 'Republican'))

> for(i in 1:length(unique(data$endog))){
+   for(j in 1:length(unique(data$dv))){
+     if(length(data$dv[data$dv == unique(data$dv)[j] & data$endog==unique(data$endog)[i]]) > 0){
+       
+       preds_white = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "white"  & data$dv == unique(data$dv)[j] ], data$se[data$endog == unique(data$endog)[i] & data$race == "white" & data$dv == unique(data$dv)[j]])
+       predictions_white = rbind(predictions_white, c(unique(data$endog)[i], unique(data$dv)[j], preds_white$est, preds_white$se, "white"))
+       
+       preds_nonwhite = meta.maker(data$coef[data$endog == unique(data$endog)[i] & data$race == "non-white" & data$dv == unique(data$dv)[j]], data$se[data$endog == unique(data$endog)[i] & data$race == "non-white" & data$dv == unique(data$dv)[j]])
+       predictions_nonwhite = rbind(predictions_nonwhite, c(unique(data$endog)[i], unique(data$dv)[j], preds_nonwhite$est, preds_nonwhite$se, "non-white"))
+       
+       
+       
+       
+       
+     }
+     
+   }
+   
+ }

> meta_plot=rbind(predictions_white, predictions_nonwhite)

> for(i in 3:(ncol(meta_plot)-2)){
+   meta_plot[,i] = as.numeric(meta_plot[,i])
+ }

> meta_plot$se =as.numeric(meta_plot$se)

> meta_plot = meta_plot[!is.na(meta_plot$ev),]

> meta_plot = meta_plot[!is.nan(meta_plot$coef),]

> plt2 = meta_plot%>%filter(ev == "Vote 2008" )%>%
+   mutate(race = factor(Hmisc::capitalize(race), levels = c('Non-white', 'White')))

> plt = rbind(plt1,plt2)

> ggsave(filename = "figures/FigS26.pdf", width=9,height=5,
+ plot = ggplot(data = plt[!plt$dv %in% c("Registered", 'Democrat', 'Republican'),], aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Future Voting') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black"))+
+   scale_fill_manual(values = c("black", "white"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("2010", "2012", '2014', '2016'))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> ggsave(filename = "figures/FigS28.pdf", width=9,height=5,
+ plot = ggplot(data = plt[plt$dv %in% c("Registered", 'Democrat', 'Republican'),]%>%
+          mutate(dv = factor(dv, levels = c('Registered', 'Democrat', 'Republican'))), aes(x = dv, y = coef, color = race, fill = race)) +
+   geom_hline(yintercept = 0, linetype = 'dotted', color = 'grey60') +
+   geom_point(shape = 21, size = 6, position=position_dodge(.5), alpha = .75) + xlab('') +
+   ylab('Effect of 2008 Voting on Registration') + 
+   geom_errorbar(aes(ymin=coef-1.96*se, ymax=coef+1.96*se, linetype = race), width=0,
+                 position=position_dodge(.5)) +
+   scale_color_manual(values = c("black", "black", "black"))+
+   scale_fill_manual(values = c("black", "white", "grey"))+
+   scale_linetype_manual(values = c('solid', 'dotdash', 'dashed'))+
+   theme_minimal()+
+   scale_x_discrete(labels = c("Registered", "Democrat", 'Republican'))+
+   theme(axis.text.y=element_text(face='bold', size =14), axis.title.y=element_text(face='bold', size =14), 
+         axis.text.x = element_text(face="bold", size =14), legend.text=element_text(face='bold', size =14),
+         legend.position="bottom", legend.spacing.x = unit(.25, 'cm'),legend.title = element_blank(), legend.key.width=unit(4,"line"))+
+   NULL
+ )

> toc()
13115.079 sec elapsed

> ####################3
> # Restore output to console
> sink() 
